콘텐츠로 건너뛰기

macOS에 MySQL 설치

macOS에 MySQL 설치 방법에 대해 알아보겠습니다. MySQL은 공식 사이트에서 직접 다운로드 받아 설치하거나 Homebrew를 사용하여 설치할 수 있습니다. 이번 포스트에서는 Homebrew를 사용하여 설치해보겠습니다.

MySQL 설치

MySQL을 설치하기 위해서는 homebrew가 먼저 설치되어 있어야 합니다.

brew install 명령을 사용하여 MySQL을 설치합니다.

$ brew install mysql
...
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 -u root

To start mysql now and restart at login:
  brew services start 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

설치가 완료되고 root 패스워드가 없는 상태로 설치가 된것을 확인할 수 있습니다.

서비스 등록하기

설치 완료 후 MySQL을 시작하고 또 macOS 로그인 시 MySQL을 자동으로 실행하도록 서비스에 등록합니다.

$ brew services start mysql
Cloning into '/opt/homebrew/Library/Taps/homebrew/homebrew-services'...
remote: Enumerating objects: 2793, done.
remote: Counting objects: 100% (486/486), done.
remote: Compressing objects: 100% (197/197), done.
remote: Total 2793 (delta 312), reused 398 (delta 282), pack-reused 2307
Receiving objects: 100% (2793/2793), 754.10 KiB | 17.95 MiB/s, done.
Resolving deltas: 100% (1349/1349), done.
Tapped 1 command (48 files, 933.7KB).
==> Successfully started `mysql` (label: homebrew.mxcl.mysql)

MySQL 보안 설정

mysql_secure_installation 명령을 사용하여 패스워드 복잡도 설정, anonymous user 삭제 등의 보안 설정을 할 수 있습니다.

$ mysql_secure_installation
VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?

Press y|Y for Yes, any other key for No:

첫 번째로 패스워드 복잡도를 설정할 지 물어봅니다. 보안 향상을 위해 사용한 것인으로 Y를 입력하고 Enter 키를 누릅니다.

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG:

패스워드 복잡도 레벨을 결정합니다. 8자 이상의 문자 + 숫자 + 특수 문자 조합을 사용 하기 위해 1번 MEDIUM을 선택합니다. 1을 입력하고 Enter 키를 누릅니다.

Please set the password for root here.

New password:
Re-enter new password:

패스워드 복잡도에 맞게 root 계정의 패스워드를 입력합니다.

Estimated strength of the password: 100
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) :

패스워드 강도를 보여주고 패스워드를 그대로 사용할지 여부를 물어봅니다. 패스워드를 제대로 입력했다면 Y를 입력하고 Enter 키를 누릅니다.

Remove anonymous users? (Press y|Y for Yes, any other key for No) :

anonymous 유저를 삭제할지 물어봅니다. Y를 입력하고 Enter 키를 눌러 anonymous 사용자를 삭제합니다.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) :

외부에서 root 계정 접속을 차단할지 여부를 물어봅니다. 보통 macOS에서는 개발환경으로 사용하기 때문에 외부에서 접속할 일이 없으므로 Y를 입력하고 Enter 키를 누릅니다.

Remove test database and access to it? (Press y|Y for Yes, any other key for No) :

테스트 데이터베이스를 삭제할지 물어봅니다. 테스트 데이터베이스를 사용하지 않는다면 Y를 입력하고 Enter 키를 누릅니다.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) :

privileges table을 갱신할지 물어봅니다. Y를 입력하고 Enter 키를 눌러 privileges를 갱신합니다.

MySQL 접속 테스트

root 계정으로 MySQL에 접속 가능한지 확인합니다.

$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 8.3.0 Homebrew

Copyright (c) 2000, 2024, 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>

root 패스워드를 입력 후 정상적으로 접속되면 MySQL 설치 및 설정이 완료되었습니다.

관련 포스트

참고 자료

태그:

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다