macOS
[macOS] MYSQL 설치 및 초기 세팅
오늘보다 더 나은 내일을 위해
2022. 4. 5. 18:02
MYSQL 설치
1. MYSQL 설치
$ brew install mysql
2. 설치 완료 후 버전 확인
$ mysql -V
mysql Ver 8.0.28 for macos12.2 on arm64 (Homebrew)
3. 서버 켜주기
$ mysql.server start
Starting MySQL
.. SUCCESS!
초기설정
$ mysql_secure_installation
1. 비밀번호 복잡성 유무 설정
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
2. 비밀번호 입력
Please set the password for root here.
New password:
Re-enter new password:
3. 익명유저 제거 여부 (MYSQL에서는 기본 설정으로 익명유저를 만듦)
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.
4. 외부에서도 root로 접속할수 있는지 설정
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.
5. 테스트 DB삭제 여부
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.
6. 권한을 변경해준 내역이 있을때 해줍니다
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_secure_installation
MYSQL 접속
1. mysql 서버 접속
$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.28 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>
2. 설정 확인
mysql> status
--------------
mysql Ver 8.0.28 for macos12.2 on arm64 (Homebrew)
Connection id: 9
Current database:
Current user: root@localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 8.0.28 Homebrew
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: utf8mb4
Db characterset: utf8mb4
Client characterset: utf8mb4
Conn. characterset: utf8mb4
UNIX socket: /tmp/mysql.sock
Binary data as: Hexadecimal
Uptime: 4 min 33 sec
Threads: 2 Questions: 5 Slow queries: 0 Opens: 115 Flush tables: 3 Open tables: 36 Queries per second avg: 0.018
--------------
MYSQL 설정파일
설정파일의 경로가 /etc/my.cnf 일 줄 알았는데 없어서 당황했다😳
아래 명령을 통해 mysql의 설정파일인 my.cnf가 위치할 수 있는 경로들의 우선순위를 확인하여 my.cnf의 위치를 확인했다.
$ mysql --help | grep my.cnf
order of preference, my.cnf, $MYSQL_TCP_PORT,
/etc/my.cnf /etc/mysql/my.cnf /opt/homebrew/etc/my.cnf ~/.my.cnf
homebrew로 설치해서 /opt/homebrew/etc/my.cnf 에 있었다.