수학과의 좌충우돌 프로그래밍

[MySQL] MacOS 에서 MySQL 설치 본문

데이터베이스/MySQL

[MySQL] MacOS 에서 MySQL 설치

ssung.k 2020. 1. 20. 01:36

제목 그대로 MacOS 에서 MySQL 을 설치하는 방법이니 다른 운영체제를 사용하시는 분들은 다른 글을 참고해주시면 감사하겠습니다.

mysql 을 설치하는 두 가지 방법에 대해서 알아보도록 하겠습니다.

해당 포스팅에서는 shell 을 사용하는 경우가 많은데 shell 에 명령어를 입력하는 것을 > 을 사용하여 나타냈습니다.

 

homebrew

homebrew 를 이용해서 설치하는 방법입니다.

homebrew 만을 사용할 때는 몰랐는데 아래서 다른 방법으로도 설치해보니 homebrew가 얼마나 편한지 세삼 실감이 납니다.

 

homebrew 를 통해 설치하기 전에는 항상 최신으로 업데이트를 해줍니다.

> brew update

 

mysql을 설치합니다.

> brew install mysql

 

설치가 완료되었는지는 버젼 확인을 통해 알아볼 수 있습니다.

> mysql --version

mysql  Ver 8.0.19 for osx10.14 on x86_64 (Homebrew)

 

mysql server 를 실행하고

> mysql.server start

Starting MySQL
.. SUCCESS!

 

설정을 해보도록 하겠습니다.

> mysql_secure_installation

 

첫번째로는 비밀번호의 validation 설정입니다.

  • yes : 비밀번호에 제약이 있음
  • no : 아무 비밀번호나 상관없음

짧고 편한 비밀번호를 위해 no 했습니다.

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:

 

위 제약에 맞춰서 패스워드를 입력합니다.

New password:

 

다음으로 익명 사용자의 제거 여부입니다.

  • yes : 제거
  • no : 제거 X

어차피 프로덕션에서는 제거해야하므로 미리 제거하겠습니다.

Remove anonymous users? (Press y|Y for Yes, any other key for No) :

 

원격 접속 가능 여부입니다.

다른 IP에서 root 로 접속하는 것을 관리합니다.

  • yes : 불가능
  • no : 가능
Disallow root login remotely? (Press y|Y for Yes, any other key for No) :

 

test 데이터베이스 유지 여부입니다.

어차피 프로덕션에서는 제거해야하므로 미리 제거하겠습니다.

  • yes : 삭제
  • no : 유지
Remove test database and access to it? (Press y|Y for Yes, any other key for No) :

 

변경된 권한을 테이블에 적용할지에 대한 설정입니다.

  • yes : 적용
  • no : 적용 X

적용 시키기 위해 yes로 설정하였습니다.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) :

 

비밀번호를 입력하고 로그인해봅시다.

-uroot 는 user 의 이름이 root 라는 뜻이고 -p 는 password 를 입력하겠다는 의미입니다.

> mysql -uroot -p

 

직접 설치

oracle 페이지에서 직접 설치하는 과정입니다.

https://dev.mysql.com/downloads/mysql/

 

MySQL :: Download MySQL Community Server

Select Operating System: Select Operating System… Microsoft Windows Ubuntu Linux Debian Linux SUSE Linux Enterprise Server Red Hat Enterprise Linux / Oracle Linux Fedora Linux - Generic Oracle Solaris macOS FreeBSD Source Code Select OS Version: All Window

dev.mysql.com

위 url 로 접속하여 제일 위에 macOS 10.15 (x86, 64-bit), DMG Archive 를 다운로드합니다.

 

 

중간에 상세 과정은 생략하고 설치가 완료되면 환경설정 에 mysql 이 설치 된 걸 확인 할 수 있고 server를 실행시켜주면 됩니다.

 

다음과 같이 설치했을 경우에는 homebrew와 달리 환경변수가 지정이 안되기 때문에 직접 해당 경로로 들어가서 명령을 내릴 수 있습니다.

> cd /usr/local/mysql/bin/
> ./mysql -uroot -p

 

환경변수 설정

본인의 환경변수를 설정하는 파일을 열어 아래 내용을 추가해줍니다.

저 같은 경우에는 zsh 를 사용하기 때문에 .zshrc 파일에 아래 내용을 입력해주었습니다.

export DB_HOME=/usr/local/mysql
export PATH="$PATH:/usr/local/mysql/bin"

 

이 다음부터는 어디서든 mysql 명령어가 사용가능합니다.

 

 

Comments