[mac] 맥에서 MariaDB 설치하기 (arm64)

neo-the-cow·2023년 2월 11일
1
post-thumbnail

맥에서 마리아디비 설치하기

0. 들어가기 전에

맥을 포멧하며 이참에 빠트렸던 것들을 하나하나 다시 기록해보자 싶어서 작성하게 됐습니다.
추후에 내가 까먹어도 다시 꺼내 볼 수 있는 가이드 문서 처럼 작성 합니다.

설치 환경과 설치 목록은 다음과 같습니다.

설치 환경
OS : macOS Ventura 13.2
설치 목록
MariaDB 10.10.3

1. 마리아디비 설치

1-1. 터미널을 열고 홈브류 업데이트

  1. 터미널을 열고 다음 명령어로 홈브류를 업데이트 해줍니다.
    홈브류가 설치되어 있지 않다면 홈브류 설치 포스트를 참고해주시면 됩니다.
% brew update
Already up-to-date.

brew : 홈브류를
update : 업데이트하라는 명령어 입니다.

  1. 홈브류가 이미 최신버전이라면 Already up-to-date.라는 응답을 출력하고, 아니라면 최신버전으로 업데이트 정보를 알려주고 brew upgrade명령어를 입력하게되면 업데이트를 진행하게 됩니다. 이미 최신버전이거나 업데이트가 끝났다면 다음 명령어로 마리아디비 레포 정보를 확인해 줍니다
% brew info mariadb
==> mariadb: stable 10.10.3 (bottled)
...
생략

brew : 홈브류로
info : 홈브류 패키지에 있는 정보를 출력하는데
mariadb : 마리아디비 패키지 정보를 출력하라는 명령어 입니다.

  1. 현재 포폴 배포 환경에서 운용중인 디비 버전이 10.10 버전인 관계로 버전 선택은 따로 하지 않고 다음 명령어로 바로 설치를 진행해줍니다.
% brew install mariadb
==> Fetching dependencies for mariadb: mecab, mecab-ipadic, msgpack, ca-certificates, openssl@1.1, pcre, groonga, pcre2, lz4, xz and zstd
==> Fetching mecab
...
생략

brew : 홈브류로
install : 설치하는데
mariadb : 마리아디비 패키지를 설치하라는 명령어 입니다.

2. 기본 설정

2-1. 루트계정 비밀번호 설정

  1. 설치가 완료되면 다음 명령어들로 마리아디비를 실행하고 접속합니다.
% brew services start mariadb
==> Tapping homebrew/services
Cloning into '/opt/homebrew/Library/Taps/homebrew/homebrew-services'...
remote: Enumerating objects: 2373, done.
remote: Counting objects: 100% (24/24), done.
remote: Compressing objects: 100% (24/24), done.
remote: Total 2373 (delta 10), reused 3 (delta 0), pack-reused 2349
Receiving objects: 100% (2373/2373), 652.27 KiB | 1.06 MiB/s, done.
Resolving deltas: 100% (1079/1079), done.
Tapped 1 command (45 files, 818.6KB).
==> Successfully started `mariadb` (label: homebrew.mxcl.mariadb)

% mariadb
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 10.10.3-MariaDB Homebrew

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

brew services start mariadb : 홈브류로 마리아디비를 실행하라는 명령어 입니다.
mariadb : 마리아디비에 접속하는 명령어 입니다.

  1. 다음 명령어로 현재 마리아디비상에 존재하는 데이터베이스를 출력합니다.
MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| test               |
+--------------------+
5 rows in set (0.005 sec)

MariaDB [(mysql)]>
  1. 다음 명령어로 mysql 데이터베이스를 선택하면 nonemysql로 변한걸 확인 할 수 있습니다.
MariaDB [(none)]> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed

MariaDB [(mysql)]>
  1. 다음 명령어로 마리아디비 계정 정보들을 불러오면 루트계정의 비밀번호 사용이 invalid되어 있는것을 확인할 수 있습니다.
MariaDB [mysql]> select host, user, password from user;
+------------------------+-------------+----------+
| Host                   | User        | Password |
+------------------------+-------------+----------+
| localhost              | mariadb.sys |          |
| localhost              | root        | invalid  |
| localhost              | neo         | invalid  |
| localhost              |             |          |
| neos-macbook-air.local |             |          |
+------------------------+-------------+----------+
5 rows in set (0.003 sec)

MariaDB [mysql]>

select host, user, password from user;
mysql 데이터베이스 내에 있는 user 테이블에서 host, user, password 정보를 가져오는 SQL문 입니다.

  1. 다음 명령어로 마리아디비 루트계정 비밀번호를 변경해주고 변경사항을 저장합니다.
    {설정 할 비밀번호}에는 마리아디비 루트계정을 사용 할 때 인증 할 비밀번호를 입력해주면 됩니다.
MariaDB [mysql]> set password for 'root'@'localhost'=password({설정 할 비밀번호})
Query OK, 0 rows affected (0.008 sec)

MariaDB [mysql]> flush privileges;
Query OK, 0 rows affected (0.002 sec)

MariaDB [mysql]>

여기서 루트계정은 맥의 루트계정이 아니라 마리아디비를 핸들링하는 마리아디비만의 루트 계정입니다.

  1. 다음 명령어로 변경사항이 잘 적용됐는지 확인하고 마리아디비를 빠져나옵니다.
MariaDB [mysql]> select host, user, password from user;
+------------------------+-------------+-------------------------------------------+
| Host                   | User        | Password                                  |
+------------------------+-------------+-------------------------------------------+
| localhost              | mariadb.sys |                                           |
| localhost              | root        | *C5D04489A537C86C08564E0C56E6630B6F9A5476 |
| localhost              | neo         | invalid                                   |
| localhost              |             |                                           |
| neos-macbook-air.local |             |                                           |
+------------------------+-------------+-------------------------------------------+
5 rows in set (0.002 sec)

MariaDB [mysql]> \q
Bye

루트계정의 비밀번호가 이상한 문자열인것은 비밀번호를 암호화해서 저장했기 때문입니다. 오류가 아닙니다.

3. 보안 설정

3-1. 기본 보안 설정

  1. 설치와 기본설정이 완료됐다면 보안설정을 해주기 위해 다음 명령어로 마리아디비를 종료해줍니다.
% brew services stop mariadb
Stopping `mariadb`... (might take a while)
==> Successfully stopped `mariadb` (label: homebrew.mxcl.mariadb)

지금 바로 진행 할 기본 보안 설정은 마리아디비 구동중에도 설정이 가능하지만 혹시모를 사고를 대비해 안전하게 실행을 종료 한 뒤에 설정합니다.

  1. 다음 명령어로 기본 보안설정을 진행합니다.
    중간중간 값을 입력해주어야하는 부분이 있기에 코드 블럭 내부에 주석(//)으로 설명 합니다.
    필요에 따라 설정값은 바뀔 수 있습니다. 본인의 상황에 맞게 설정해주세요!!
// sudo : 관리자권한으로 다음을 실행하라는 명령어입니다.
% sudo mariadb-secure-installation
// 맥의 루트계정 비밀번호를 입력합니다. 따로 설정되어있지 않을 경우 엔터키를 누르면 진행됩니다.
Password:

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
haven't set the root password yet, you should just press enter here.

// 현재 마리아디비 루트계정의 비밀번호(위에서 설정한 비밀번호)를 입력해줍니다.
Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password or using the unix_socket ensures that nobody
can log into the MariaDB root user without the proper authorisation.

You already have your root account protected, so you can safely answer 'n'.

// 마리아디비 계정을 유닉스 소켓을 통해 인증하겠습니까? 아니오.
Switch to unix_socket authentication [Y/n] n
 ... skipping.

You already have your root account protected, so you can safely answer 'n'.

// 현재 마리아디비 루트 계정의 비밀번호를 바꾸시겠습니까? 아니오.
Change the root password? [Y/n] n
 ... skipping.

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB 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? [Y/n] y
 ... Success!

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? [Y/n] n
 ... skipping.

By default, MariaDB 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? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

// 권한정보를 새로고침 하시겠습니까? 예.
Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!
  1. 설정이 완료됐으면 다음 명령어로 마리아디비를 다시 구동합니다.
% brew services mariadb start

4. 맺음말

이렇게 맥에 마리아디비 설치가 완료됐습니다.
% mariadb -V 명령어로 현재 설치된 마리아디비의 버전을 확인 할 수 있습니다.

다음 포스팅에서는 디비를 핸들링 할 gui 앱을 소개하겠습니다.

혹시나 오류가 발생한다거나 결과가 올바르지 않다면 중간에 오탈자는 없었는지, 빠진건 없는지 한번 다시 확인해 주시고 이해가 안되는 부분이 있다면 댓글로 남겨주시면 확인하는 대로 답변 달겠습니다.

profile
Hi. I'm Neo

2개의 댓글

comment-user-thumbnail
2023년 12월 6일

안녕하세요, 잘 보고 설치했습니다! 감사합니다.
다만 보안 설정 과정에서, mariadb를 종료해버린 상태로 보안 설정을 진행하고자 하면 socket 파일이 없다고 절차가 진행되지 않아서 저는 mariadb를 켜놓은 상태로 보안 설정을 진행하였는데, 이 부분을 확인해주실 수 있을까요?

1개의 답글