2022.3.12.
% 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
==> Casks
mysql-connector-python mysql-utilities navicat-for-mysql
mysql-shell mysqlworkbench ✔ sqlpro-for-mysql
# 최신 mysql 패키지를 다운
% brew install mysql
==> 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 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
# mysql@버전 : 원하는 버전을 선택하여 다운
% brew install mysql@5.7
# mysql-client는 커맨드라인에서 mysql 서버 접속시 사용
% brew install mysql-client
# GUI for MySQL
% brew install --cask mysqlworkbench
# brew list를 통해 설치된 항목을 조회
% brew list
==> Formulae
mysql
% brew remove mysql
% echo 'export PATH="/opt/homebrew/opt/mysql-client/bin:$PATH"' >> ~/.zshrc
% echo 'export PATH="/opt/homebrew/opt/mysql/bin:$PATH"' >> ~/.zshrc
% source ~/.zshrc
# MySQL 서버 실행
% mysql.server start
Starting MySQL
. SUCCESS!
# MySQL 서버 중지
% mysql.server stop
Shutting down MySQL
. SUCCESS!
mysql_secure_installation
명령어 입력# MySQL 기본적인 보안을 강화 설정을 하기 위해서 `mysql_secure_installation` 명령어를 입력
% mysql_secure_installation
비밀번호 가이드 설정에 대한 질문
Yes : 복잡한 비밀번호 설정
No : 쉬운 비밀번호 설정
Securing the MySQL server deployment.
Connecting to MySQL using a blank password.
VALIDATE PASSWORD PLUGIN 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 plugin?
Press y|Y for Yes, any other key for No:
사용할 새로운 비밀번호를 입력
비밀번호 : 0000
Please set the password for root here.
New password:
Re-enter new password:
mysql -u root
처럼 -u 옵션 필요mysql
처럼 -u 옵션 불필요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
다른 IP에서 root 아이디로 원격접속을 허용하는지에 대한 설정
Yes : 원격접속 불가능
No : 원격접속 가능
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) : No
Test 데이터베이스를 설정하는 질문
Yes : Test 데이터베이스 제거
No : Test 데이터베이스 유지
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
변경된 권한을 테이블에 적용하는 설정에 대한 질문
Yes : 적용 시킨다
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
All done!이 뜨면 모든 설정 완료
% mysql_secure_installation
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
Please set the password for root here.
New password:
Re-enter new password:
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.
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) : no
... skipping.
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.
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!
# 서버 실행 후
% mysql -u root -p
Enter password:
% mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.35 Homebrew
Copyright (c) 2000, 2021, 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> exit or quit
Bye
# MySQL 서버 시작 :
% mysql.server start
# MySQL DB 로그인 :
% mysql -u root -p
Enter password: 0000
# MySQL DB 로그아웃 :
mysql> exit 또는 quit
# MySQL 서버 종료 :
% mysql.server stop