[MySQL] M1칩 Mac에서 Homebrew로 MySQL 설치하기

xii·2023년 4월 14일
0

MySQL과 Mac

MacOS에서는 Homebrew를 통해 각종 프로그램을 간단하게 설치할 수 있다.
단, 명령어를 안다는 가정이 기본 전제로 깔려 있다.

MySQL을 새로 설치하려 여러 포스트를 뒤져 보았지만 M1칩 Mac에서 설치하는 방법이랑은 다른 글이 많았기에 작성한다.


설치(1) - 기본 프로그램

HomeBrew

Homebrew는 MacOS의 패키지 관리자이다.
프로그램 설치, 삭제 및 관리를 간편하게 할 수 있도록 돕는다.

Homebrew 공식 홈페이지

홈페이지에 가면 가장 먼저 명령어가 보이는데, 이 명령어를 터미널에 붙여넣기 해준다.

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

이후 Mac의 비밀번호를 입력하고 엔터를 친다.
Mac 터미널에서는 비밀번호를 입력해도 입력이 되었는지 알 수가 없는데, 이 탓에 잘못 입력하기 쉽다. 아무것도 입력이 안 된 것 같아도 입력이 되었을 수 있으니 주의하자.

바로 Homebrew를 활용해 MySQL과 Cask, Openssl이 설치되어 있는지 체크해보자.

brew services // MySQL 확인
brew list // cask, openssl 확인

cask

cask는 MacOS의 유틸리티 프로그램으로, 명령어 한 줄을 통해 간단히 MacOS용 프로그램을 설치할 수 있도록 한다.

brew install cask

설치(2) - MySQL

brew search mysql

search 명령어를 통해 자신이 깔고 싶은 MySQL 버전을 확인하자.

brew install mysql은 기본적으로 stable한 최신 버전의 MySQL을 설치하므로 이전 버전을 설치하고 싶을 경우 search를 해주어야 한다.

본인의 경우 최신 버전 설치를 했으므로 이를 기준으로 작성했다.

// 설치 명령어

brew install mysql

MySQL root 계정 비밀번호 설정

설치가 완료되었으면 root 계정의 비밀번호를 설정해주자.

mysql_secure_installation을 입력하면 root 계정의 비밀번호를 설정할 수 있다.

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: 

보안의 향상을 위해 유효한 비밀번호만을 허용하는 옵션이다.
필자는 Y를 선택했으나 굳이 필요는 없다고 생각한다...

다음은 Y를 입력했을 경우 뜨는 옵션이다.
비밀번호의 강도와 옵션을 선택할 수 있다.

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0

0번 LOW의 경우 길이만 제한이 있고,
1번 MEDIUM의 경우 길이와 대소문자, 숫자, 특수문자를 섞어야 한다.
2번 STRONG의 경우 길이, 대소문자, 숫자, 특수문자,dictionary가 필요하다.
dictionary가 무엇인지는 잘 모르겠다.

아무튼 LOW인 0번을 선택했다.

이러면 이제 비밀번호를 설정할 수 있다.

New password:

Re-enter new password:

역시나 비밀번호를 입력했는지 안 했는지 모르게 빈 칸이다.
당황하지 말고 위에서 설정한 강도에 따라 비밀번호를 설정해준다.

Estimated strength of the password: 50 // 비밀번호 강도
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : 

이 비밀번호로 계속하겠냐는 질문인 것 같다.
yes를 선택하고 넘어갔다.

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

기본적으로 MySQL을 설치하면 anonymouse user (익명의 사용자)가 MySQL에 접근하는 것을 허용하기 위해 anonymouse user 계정이 있다고 한다. 이를 삭제할 것인지 물어보는 질문이다.
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) :

root 계정의 연결을 localhost에서만 허용하겠냐는 질문이다.
yes를 선택하고 넘어갔다.

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

누구나 접근할 수 있는 test 데이터베이스가 있는데 이는 프로덕션 환경으로 이동하기 전에 제거해야 한다고 한다. 이를 삭제할 것인지 묻는 질문이다.
이건 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를 눌러 변경사항을 적용하자.


설치 과정에서 발생하는 에러

Error: can't connect to local mysql server through socket '/tmp/mysql.sock' (2)

  • brew service start 명령어

    	이 경우는 brew를 통해 처음 MySQL을 설치한 직후 곧바로 mysql -u root -p 등의 명령어를 입력한 경우이다.
    	brew serice start를 통해 서비스를 시작해주도록 하자.
  • cd 명령어로 경로 이동 후 ./mysql.server start 입력하기

    	경로를 똑바로 찾지 못해 에러가 발생한 경우로 예상한다.
    	이 경우에는 디렉토리를 직접 이동해서 실행해주도록 하자.
  • 재설치

    	sudo brew services stop mysql // mysql 멈추기
    
    	brew uninstall mysql // brew에서 mysql 삭제
    
    	rm -rf /opt/homebrew/var/mysql // 로컬 폴더 삭제
    
    	brew install mysql // 재설치
profile
내가 그다지 사랑하던 그대여 내 한평생에 차마 그대를 잊을 수 없소이다 내 차례에 못 올 사랑인 줄은 알면서도 나혼자는 꾸준히 생각하리라 자 그러면 내내 어여쁘소서 - 이상, <이런 시>

0개의 댓글