기본적으로 mariadb를 설치를 하고 나면 기본 홈 디렉토리 (데이터베이스 저장)가 /var/lib/mysql 경로이다
1 2 3 4 5 6 7 |
MariaDB [(none)]> select @@datadir; +-------------------+ | @@datadir | +-------------------+ | /var/lib/mysql/ | +-------------------+ 1 row in set (0.000 sec) |
해당 디렉토리를 변경을 해보자 / 여라가지 이유 / 저장공간의 이슈등
1. mariadb 중지
1 |
[root@xinet ~]# systemctl stop mariadb |
2. 변경할 디렉토리로 /var/lib/mysql 폴더 복사 및 기존폴더 mv
1 2 3 4 |
[root@xinet ~]# cp -a /var/lib/mysql /home/mysql_data ### 원래폴더 mv [root@xinet ~]# mv /var/lib/myslq /var/lib/myslq.old |
3. my.cnf 파일에서 디렉토리 내용 추가
1 2 3 4 5 6 7 8 9 10 11 |
[root@xinet ~]# vi /etc/my.cnf.d/server.cnf [client] port=3306 socket=/home/mysql_data/mysql.sock [mysqld] #datadir datadir=/home/mysql_data/ socket=/home/mysql_data/mysql.sock |
4. 서비스 실행파일 내용 수정
1 2 |
[root@xinet /var/lib]# vi /usr/lib/systemd/system/mariadb.service ProtectHome=false |
5. 대몬 적용
1 |
[root@xinet ~]# systemctl daemon-reload |
6. 서비스 시작 및 확인
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
[root@xinet ~]# systemctl start mariadb ### 서비스 확인 [root@xinet ~]# systemctl status mariadgb Unit mariadgb.service could not be found. [root@xinet ~]# systemctl status mariadb ● mariadb.service - MariaDB 11.4.2 database server Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled) Drop-In: /etc/systemd/system/mariadb.service.d └─migrated-from-my.cnf-settings.conf Active: active (running) since Thu 2024-05-30 10:24:43 KST; 49s ago Docs: man:mariadbd(8) https://mariadb.com/kb/en/library/systemd/ Process: 11112 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS) Process: 10999 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= || VAR=`cd /usr/bin/..; /usr/bin/galera_recovery`; [ $? -eq 0 ] && systemctl set-environment _WSRE> Process: 10997 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS) Main PID: 11096 (mariadbd) Status: "Taking your SQL requests now..." |
7. mysql 접속 후 datadir 경로 확인
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
[root@xinet ~]# mysql -u root -p mysql mysql: Deprecated program name. It will be removed in a future release, use '/usr/bin/mariadb' instead Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 3 Server version: 11.4.2-MariaDB MariaDB Server 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)]> select @@datadir; +-------------------+ | @@datadir | +-------------------+ | /home/mysql_data/ | +-------------------+ 1 row in set (0.000 sec) |
경로가 변경된것을 확인 할 수 있다
이제 앞으로 데이터베이스를 만들거나 테이블 만들면 해당 리렉토리에 저장이 된다