All about

M1 맥북에 MariaDB, MySQL를 설치하려고 하니 시행착오를 많이 겪었습니다. MySQL 설치 과정을 정리합니다.(MariaDB) 이 글을 보시는 분들이 바로 사용할 수 있도록 터미널 결과를 복사해서 글을 작성했습니다.

 

1. homebrew의 install 커맨드로 설치합니다.

root@MacBookAir / % brew install mysql
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> Updated Formulae
Updated 59 formulae.
==> Downloading https://ghcr.io/v2/homebrew/core/mysql/manifests/8.0.29
Already downloaded: /Users/root/Library/Caches/Homebrew/downloads/7e1024303fbfa1839b3a1eee037d5a086214c4ce033c85a30a26685993dc6c43--mysql-8.0.29.bottle_manifest.json
==> Downloading https://ghcr.io/v2/homebrew/core/mysql/blobs/sha256:041bae356a31fb942e57827c7bcacd327dafaf9ae30f2654c65758d8053c282b
Already downloaded: /Users/root/Library/Caches/Homebrew/downloads/15687d063875845c84db47d170f70130f4498ac87586d27998a3eb0d59b98d58--mysql--8.0.29.arm64_big_sur.bottle.tar.gz
==> Pouring mysql--8.0.29.arm64_big_sur.bottle.tar.gz
==> Caveats
We’ve installed your MySQL database without a root password. To secure it run:
  mysql_secure_installation
MySQL is configured to only allow connections from localhost by default
To connect run:
  mysql -uroot
To restart mysql after an upgrade:
 brew services restart mysql
Or, if you don’t want/need a background service you can just run:
 /opt/homebrew/opt/mysql/bin/mysqld_safe --datadir=/opt/homebrew/var/mysql
==> Summary
:beer: /opt/homebrew/Cellar/mysql/8.0.29: 311 files, 296.2MB
==> Running `brew cleanup mysql`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).

 

2. 설치 후에 나오는 안내 문구대로 "mysql -uroot" 를 통해 실행하면 아래와 같은 에러메세지가 출력됩니다.

root@MacBookAir / % mysql -uroot
ERROR 1698 (28000): Access denied for user ‘root’@‘localhost’

sudo 를 통해 실행하면 됩니다.

root@MacBookAir / % sudo mysql -uroot
Password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.5.5-10.7.3-MariaDB Homebrew
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.
mysql>

"mysql"로도 잘 실행됩니다.

root@MacBookAir / % mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.5.5-10.7.3-MariaDB Homebrew
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.
mysql>

 

Error case

1. homebrew로 설치했기 때문에, "mysql.server start" 명령어를 사용할 경우 아래와 같이 에러메세지가 출력됩니다. 

root@MacBookAir / % mysql.server start
Starting MySQL
. ERROR! The server quit without updating PID file (/opt/homebrew/var/mysql/MacBookAir.local.pid).

저는 이걸 몰라서 homebrew로 설치 후에 "brew services start mysql" 혹은 "brew services restart mysql" 로 실행하지 않았기 때문에 문제가 발생했었습니다.

 

2. 안내 문구를 보면 "mysql_secure_installation"을 통해서 root password를 설정할 수 있습니다. 그냥 실행할경우엔 아래처럼 에러가 발생합니다. 앞에 sudo 를 붙여서 실행하면 정상적으로 동작합니다.

root@MacBookAir / % mysql_secure_installation
Securing the MySQL server deployment.
Enter password for user root:
Error: Access denied for user ‘root’@‘localhost’

공유하기

facebook twitter kakaoTalk kakaostory naver band
loading