[Database][MySQL][MacOS] MySQL 설치 for MacOS

seony·2022년 7월 6일
0

macOS에서 homebrew을 이용하여 MySQL을 설치하는 과정을 기록한다.

설치 전 homebrew를 최신으로 갱신

% brew update

homebrew에 MySQL package 있는지 확인

% brew search mysql
==> Formulae
automysqlbackup           mysql-client              mysql-sandbox             mysql@5.7
mysql                     mysql-client@5.7          mysql-search-replace      mysqltuner
mysql++                   mysql-connector-c++       mysql@5.6                 qt-mysql

MySQL

기존 설치 여부 확인

% mysql -V
zsh: command not found: mysql

설치

% brew install mysql

아래와 같이 나오면 설치가 완료된 것이다.

==> Installing mysql
==> Pouring mysql--8.0.29.monterey.bottle.tar.gz
==> /usr/local/Cellar/mysql/8.0.29/bin/mysqld --initialize-insecure --user=seony --basedir=/usr/local/C
==> 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:
  /usr/local/opt/mysql/bin/mysqld_safe --datadir=/usr/local/var/mysql
==> Summary
🍺  /usr/local/Cellar/mysql/8.0.29: 311 files, 294.7MB
==> Running `brew cleanup mysql`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
==> Caveats
==> 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 -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:
  /usr/local/opt/mysql/bin/mysqld_safe --datadir=/usr/local/var/mysql

그리고 버전을 확인한다.

% mysql -V
mysql  Ver 8.0.29 for macos12.2 on x86_64 (Homebrew)

DB 구동

% mysql.server start

Starting MySQL
. SUCCESS! 

DB 설정

MySQL이 무사히 구동되었다면, 아래의 명령을 실행하여 DB 설정을 한다. 이 명령어는 DB 설정을 변경하고 싶을 때 실행하여 DB 설정을 다시 할 수 있다.
% mysql_secure_installation

비밀번호 설정

비밀번호 복잡성 설정 여부 선택

복잡한 비밀번호 설정 여부를 확인한다. 복잡한 비밀번호로 설정할려면 YES, 아니면 NO를 명시한다.
Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

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: NO

root 비밀번호 설정

Please set the password for root here.

New password: 

Re-enter new password: 

Anonymous User ( 익명유저 )

MySQL에서 기본적으로 제공하는 Anonymous user를 생성하는 이를 허용할지 여부 설정한다. Anonymous user를 생성하고자 하면 YES, 생성을 원하지 않는다면 NO를 입력한다.
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

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

root 접속 권한

root 계정 접속을 localhost만 허용할지, 원격에서도 접속할 수 있도록 허용할지 선택한다. root 계정에 대한 원격접속을 허용하지 않으면 YES, 허용하면 NO를 입력한다. 보안을 위해 YES를 추천한다.
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

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

TEST Database 생성 여부

TEST Database를 생성하지 않으면 YES를, 생성할려면 NO를 입력한다.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


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

 - Removing privileges on test database...
Success.

Privilege Table Reload 여부

변경 사항을 적용하기 위해 Privilege table을 reload 여부를 결정한다. 즉시 Privilege Table을 reload 하고자하면 YES, reload 하지 않을려면 NO를 입력한다.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

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

All done! 

DB 접속

% mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.29 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> 

DB 종료

DB 종료한다. DB를 종료하면 connect 시 에러가 발생한다.
% mysql.server stop
Shutting down MySQL
. SUCCESS! 

% mysql -u root -p 
Enter password: 
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
profile
Developer

0개의 댓글

관련 채용 정보