안녕하세요. 클스 입니다.
오늘은 Mac에 MariaDB를 설치해보고자 합니다. 역시 공부를 하려면 테스트 환경을 구축을 먼저 해야 되겠네요~
[~]$ brew install mariadb
이것저것 필요한 라이브러리 설치하고 한 5분 걸리네요~
==> Pouring mariadb--10.11.3.ventura.bottle.tar.gz
==> /usr/local/Cellar/mariadb/10.11.3/bin/mysql_install_db --verbose --user=keunsookim --basedir=/usr/local/Cellar/mariadb/10.11.3 --datadir=/usr/local/var/mysql --tmpdir=/tmp
설치된 디렉토리 잘 확인해주세요~
설치 됐는지 버전을 확인해봅시다.
[~]$ mariadb -v
ERROR 2002 (HY000): Can't connect to local server through socket '/tmp/mysql.sock' (2)
에러가 나네요 한번에 잘될리가~~ MariaDB가 mysql에서 옆으로 발전한거라 아직도 파일명이 mysql 이 나오네요~
위에 설치한 터미널 로그를 보니 아래 오류가 나네요~
==> Installing virtualenv
==> Pouring virtualenv--20.23.0.arm64_ventura.bottle.tar.gz
Error: The `brew link` step did not complete successfully
설치한 기억이 없는데.... 그래서 삭제 해봅니다.
[~]$ brew uninstall --ignore-dependencies virtualenv
Uninstalling /opt/homebrew/Cellar/virtualenv/20.23.0... (930 files, 14.4MB)
일단 원인을 알아봐야 하겠지만 그래도 혹시나 업데이트를 해봅니다.
[~]$ brew upgrade
그리고 정말 mariadb 가 설치되어 있는지 확인
[~]$ which mariadb
/opt/homebrew/bin/mariadb
혹시나 서비스가 떠있나 확인해봅니다.
[~]$ brew services list
Name Status User File
mariadb none
[~]$
MariaDB를 서비스로 실행해 봅니다.
[~]$ brew services start mariadb
==> Successfully started `mariadb` (label: homebrew.mxcl.mariadb)
[~]$
이런 안내도 뜨네요~
다시 버전을 확인 해보니 아래와 같이 뜹니다. 웹에 원인을 이전 파일이 남아있어 문제,
그래서 재설치가 많았습니다.
제 경우는 service를 실행안한 상태에서 mariadb -v 를해서 문제가 된것 입니다.
[~]$ mariadb -v
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 10.11.3-MariaDB Homebrew
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Reading history-file /Users/keulstar/.mysql_history
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
데이터 베이스가 잘 설치된 것을 확인할 수 있습니다.
MariaDB [(none)]> quit;
재부팅을 한 이유는 맥이 13.4 업그레이되었네요~ 다시 mariadb 에 접속 해봅니다. 자동으로 서비스가
실행되었네요~ 그런데 무슨 계정으로 접속한건지 ? ㅎㅎ
Last login: Wed May 24 23:19:25 on console
[~]$ mariadb -v
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 10.11.3-MariaDB Homebrew
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Reading history-file /Users/keulstar/.mysql_history
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> use test
Database changed
MariaDB [test]> show tables;
--------------
show tables
--------------
Empty set (0.001 sec)
MariaDB [test]>
test db에 아무것도 없네요~
[~]$ mariadb -uroot
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
[~]$
root로 접속해보려 하니 이런 오류가 나네요~ root로는 접속 못한다.... 역시 sudo 가 최고 입니다.
[~]$ sudo mariadb -u root
Password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 5
Server version: 10.11.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)]>

MariaDB [mysql]> ALTER user 'root'@'localhost' identified by 'YOURPASSWORD' ;
Query OK, 0 rows affected (0.007 sec)
이렇게 root password를 셋팅해줍니다.
[~]$ mariadb -u root -p
Enter password: YOURPASSWORD 를 입력해줍니다. 아래와 같이 접속되는 것을 확인할 수 있습니다.
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 10.11.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)]>
Mariadb 에서는 my.cnf에서 character set 등 여러가지 변수를 변경할 일이 많습니다.
home brew로 설치하면 my.cnf가 어디 있을까요 ?
$ vi /opt/homebrew/etc/my.cnf. ==> 이 파일에는 별거 없습니다.
다시 찾아 봅니다.
[~]$ mariadb --help | grep my.cnf
/opt/homebrew/etc/my.cnf ~/.my.cnf
order of preference, my.cnf, $MYSQL_TCP_PORT,
[~]$ brew services stop mariadb
아래 3개의 파일을 만듭니다.
[stable][/opt/homebrew/etc/my.cnf.d]$ vi client.cnf
[stable][/opt/homebrew/etc/my.cnf.d]$ vi mysql-clients.cnf
[stable][/opt/homebrew/etc/my.cnf.d]$ vi server.cnf
아래와 같이 붙혀 넣어주세요. 그리고 mariadb 재시작 합니다.
/etc/my.cnf.d/client.cnf
[client]
default-character-set=utf8
/etc/my.cnf.d/mysql-clients.cnf
[mysql]
default-character-set=utf8
[mysqldump]
default-character-set=utf8
/etc/my.cnf.d/server.cnf
[mysqld]
collation-server = utf8_general_ci
init-connect='SET NAMES utf8'
character-set-server = utf8
MariaDB [(none)]> show variables like 'c%';
해보시면 이전에 collation_database latin1 --> utf8mb3_general_ci 이렇게 변경되어 있습니다.
주의할 점은 문자셋을 변경했으면 기존 db를 삭제하고 다시 만들어주세요
만약 해둔게 많으시다면 아래와 같이 할수 있지만 잘 안되네요~
그래서 무조건 제일 먼저 mariadb 설치 후에는 character set 을 변경하고 재시작 해줘야 합니다.
ALTER DATABASE `test`
DEFAULT CHARACTER SET utf8mb3
DEFAULT COLLATE utf8mb3_general_ci;
안에 있던 테이블도 다 문자셋을 변경해줘야 합니다.
ALTER DATABASE `test`
DEFAULT CHARACTER SET utf8mb3
DEFAULT COLLATE utf8mb3_general_ci;
이상 클스 였습니다.
댓글
댓글 쓰기