homebrew둜 MySQL νŒ¨ν‚€μ§€ μ„€μΉ˜ 방법

MySQL νŒ¨ν‚€μ§€ 검색

> 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 νŒ¨ν‚€μ§€λ₯Ό λ‹€μš΄λ°›μ„ 수 μžˆμŠ΅λ‹ˆλ‹€.
  • brew install mysql@5.7 : mysql 5.7버전 νŒ¨ν‚€μ§€λ₯Ό λ‹€μš΄λ°›μ„ 수 μžˆμŠ΅λ‹ˆλ‹€.

mysql@버전 : μ›ν•˜λŠ” 버전을 μ„ νƒν•˜μ—¬ λ‹€μš΄λ°›μ„ 수 μžˆμŠ΅λ‹ˆλ‹€.

mysql@5.7을 μ„€μΉ˜ν•˜μ˜€μŠ΅λ‹ˆλ‹€.

MySQL μ„€μΉ˜ 확인 방법

  • brew listλ₯Ό 톡해 μ„€μΉ˜λœ ν•­λͺ©μ„ μ‘°νšŒν•  수 μžˆμŠ΅λ‹ˆλ‹€.
> brew list
mysql@5.7

MySQL μ‚­μ œ 방법

  • brew remove mysql@5.7

brew listλ₯Ό 톡해 μ‚­μ œλ˜μ—ˆλŠ”μ§€ 확인이 κ°€λŠ₯ν•©λ‹ˆλ‹€.

MySQL μ„€μ • 방법

ν™˜κ²½ λ³€μˆ˜ μΆ”κ°€

  • bash shell이 μ•„λ‹Œ zsh shell을 κΈ°μ€€μœΌλ‘œ μž‘μ„±ν•˜μ˜€μŠ΅λ‹ˆλ‹€
> echo 'export PATH="/usr/local/opt/mysql@5.7/bin:$PATH"' >> ~/.zshrc

ν™˜κ²½ λ³€μˆ˜ 적용

> source ~/.zshrc

MySQL μ„œλ²„ μ‹€ν–‰/쀑지

mysql.server start λͺ…λ Ήμ–΄λ‘œ MySQL μ„œλ²„λ₯Ό μ‹€ν–‰μ‹œν‚΅λ‹ˆλ‹€.

> mysql.server start
Starting MySQL
 SUCCESS!

mysql.server stop λͺ…λ Ήμ–΄λ‘œ MySQL μ„œλ²„λ₯Ό μ€‘μ§€μ‹œν‚¬ 수 μžˆμŠ΅λ‹ˆλ‹€.

MySQL μ„€μ •

MySQL 섀정을 ν•˜κΈ° μœ„ν•΄μ„œλŠ” mysql_secure_installation λͺ…λ Ήμ–΄λ₯Ό μž…λ ₯ν•©λ‹ˆλ‹€.

mysql_secure_installation

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:

λΉ„λ°€λ²ˆν˜Έ μœ ν˜• 선택

λΉ„λ°€λ²ˆν˜Έ κ°€μ΄λ“œ 섀정에 λŒ€ν•œ μ§ˆλ¬Έμž…λ‹ˆλ‹€.

  • Yes : λ³΅μž‘ν•œ λΉ„λ°€λ²ˆν˜Έ μ„€μ •
  • No : μ‰¬μš΄ λΉ„λ°€λ²ˆν˜Έ μ„€μ •
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

Noλ₯Ό μ„ νƒν–ˆμŠ΅λ‹ˆλ‹€.

λΉ„λ°€λ²ˆν˜Έ μ„€μ •

μ‚¬μš©ν•  μƒˆλ‘œμš΄ λΉ„λ°€λ²ˆν˜Έλ₯Ό μž…λ ₯ν•©λ‹ˆλ‹€.

Please set the password for root here.

New password:

Re-enter new password:

λΉ„λ°€λ²ˆν˜ΈλŠ” κ°„λ‹¨ν•˜κ²Œ mysql둜 ν–ˆμŠ΅λ‹ˆλ‹€.

μ‚¬μš©μž μ„€μ •

Remove anonymous users? (Press y|Y for Yes. any other key for No)
μ‚¬μš©μž 섀정을 ν•˜λŠ” λΆ€λΆ„μž…λ‹ˆλ‹€.

  • Yes : μ ‘μ†ν•˜λŠ” 경우 mysql -u root처럼 -u μ˜΅μ…˜ ν•„μš”
  • No : μ ‘μ†ν•˜λŠ” 경우 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

Yesλ₯Ό μ„ νƒν–ˆμŠ΅λ‹ˆλ‹€.

원격 접속 μ„€μ •

Disallow root login remotely? (Press y|Y for Yes, any other key for No)
λ‹€λ₯Έ 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

Yesλ₯Ό μ„ νƒν–ˆμŠ΅λ‹ˆλ‹€.

TEST λ°μ΄ν„°λ² μ΄μŠ€ μ„€μ •

Remove test database and access to it? (Press y|Y for Yes, any other key for 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λ₯Ό μ„ νƒν–ˆμŠ΅λ‹ˆλ‹€.

λ³€κ²½λœ κΆŒν•œμ„ ν…Œμ΄λΈ”μ— μ μš©ν•˜λŠ” μ„€μ •

Reload privilege tables now? (Press y|Y for Yes, any other key for No)
λ³€κ²½λœ κΆŒν•œμ„ ν…Œμ΄λΈ”μ— μ μš©ν•˜λŠ” 섀정에 λŒ€ν•œ μ§ˆλ¬Έμž…λ‹ˆλ‹€.

  • 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

Yesλ₯Ό μ„ νƒν–ˆμŠ΅λ‹ˆλ‹€.

μ„€μ • μ™„λ£Œ

  • All done!이 뜨면 λͺ¨λ“  섀정이 λμž…λ‹ˆλ‹€.

MySQL DB 둜그인/λ‘œκ·Έμ•„μ›ƒ

mysql -uroot -p λͺ…λ Ήμ–΄λ₯Ό μž…λ ₯ν›„ μœ„μ—μ„œ μ„€μ •ν•œ λΉ„λ°€λ²ˆν˜Έλ₯Ό μž…λ ₯ν›„ λ‘œκ·ΈμΈν•©λ‹ˆλ‹€.

> mysql -uroot -p
Enter password:
  • μ •μƒμ μœΌλ‘œ 둜그인이 되면 mysql> λ‚˜μ˜΅λ‹ˆλ‹€.
> mysql -uroot -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 λͺ…λ Ήμ–΄λ‘œ λ‘œκ·Έμ•„μ›ƒν•  수 μžˆμŠ΅λ‹ˆλ‹€.

mysql> exit or quit
Bye

MySQL μ‹€ν–‰ 절차

  1. MySQL μ„œλ²„ μ‹œμž‘ : mysql.server start
  2. MySQL DB 둜그인 : mysql -uroot -p
  3. MySQL DB λ‘œκ·Έμ•„μ›ƒ : exit λ˜λŠ” quit
  4. MySQL μ„œλ²„ μ’…λ£Œ : mysql.server stop

reference

macOS MySQL μ„€μΉ˜ 및 μ„€μ • μ‚¬μš©λ²•
MySQL μ„€μΉ˜μ™€ 초기 μ„€μ • for macOS
MacOS brew둜 mysql5.7 μ„€μΉ˜
mysql5.7 버전 homebrew 둜 μ„€μΉ˜