본문 바로가기
개발

[Mac OS] homebrew를 이용한 mysql 설치 및 세팅 방법

by 준형 교수 2024. 3. 15.

먼저 터미널을 실행해 줍니다. (이 과정은 homebrew가 설치가 되어있어야 합니다.)

 

[Step 1] brew install mysql <- 을 입력하여 mysql을 설치합니다.

이렇게 설치하는 경우 가장 최신 버전의 mysql이 설치가 되며 특정버전의 mysql 설치가 필요하신 분들은
Ex) brew install mysql@5.7처럼 @버전을 뒤에 추가하여 특정 버전의 mysql을 설치합니다.

설치가 완료되면 다음과 같은 안내문구가 출력됩니다.

Caveats (주의사항)을 읽어보시면 root 계정 비밀번호 설정 없이 mysql만 설치되어 있다고 나와있습니다.
아래에 안내해 주는 명령어 mysql_secure_installation을 통해 설정을 마저 해야지 mysql 설정이 완료됩니다.

그리고 아래에 시작프로세스에 등록하여 컴퓨터 부팅하면 mysql도 자동으로 실행해 주는 명령어도 안내해주고 있습니다.
brew services start mysql <
저는 필요할 때 직업 실행시켜서 사용할 것이기에 이 과정은 넘기겠습니다.

 

[Step 2] mysql_secure_installation으로 나머지 설정을 마저 해보겠습니다.

세팅에 마저 하기 위해 먼저  mysql을 실행을 시켜줍니다.

mysql.server start < 명령어를 통해 mysql을 실행시킵니다.

 

Starting MySQL.. SUCCESS!

가 출력되었다면 이제 mysql_secure_installation 명령어를 입력하여 나머지 세팅을 진행하여 줍니다.


1. 비밀번호 복잡도 검사

 

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

비밀번호 복잡도 검사를 적용할 것인지 설정하는 과정입니다. 복잡도 검사를 적용하게 된다면 다음과 같은 비밀번호 조건이 붙습니다.
- 최소 8자리 이상의 비밀번호
- 최소 1개의 영문자
- 최소 1개의 특수문자
- 최소 1개의 숫자

간단하게 비밀번호를 설정해 두실 분들은 No로 진행하면 됩니다.

이후 설정할 비밀번호 입력이 나오는데 입력해도 보이지 않는 것이 정상입니다.


2. 익명의 사용자 삭제


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로 삭제해 줍니다.


3. 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)

root 계정을 원격(외부)에서의 접속을 차단할 것인지 묻습니다. 일반적인 경우라면 root 계정은 원격 접속은 차단해 두는 것이 권장됩니다. Yes로 차단을 하여 주시면 됩니다. 원격작업이 필요한 경우는 root 말고 db 계정을 따로 생성하여 원격 권한을 주는 것이 가장 바람직합니다.


4. 테스트 데이터베이스 삭제


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로 버려주셔도 됩니다.


5. 현재까지의 변경사항 즉시 적용
 
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를 통해 변경사항을 즉시 적용시켜 줍니다.

 


[Step 3] mysql 로그인 테스트 및 프로그램 종료

이제 기본 설정이 완료된 root로 로그인을 해보겠습니다.
> mysql -u root -p

(-u 뒤에는 접속할 계정을 입력하면 됩니다. 저희는 방금 설정한 root로 로그인 테스트를 해보겠습니다.)

(-p는 비밀번호를 이용하여 접속한다는 의미입니다.)

 

mysql 사용이 끝나면 exit를 입력하여 사용자 접속을 종료한 후 mysql.server stop을 입력하여 실행 중인 mysql 서버를 종료시켜 줍니다


이것으로 기본적인 mysql 설치 및 세팅은 마무리되었습니다. 편리한 사용을 위해 workbench 같은 gui 툴도 필요하신 분들은 설치해 주시면 도움이 됩니다.