CentOS修改Mariadb資料庫檔案儲存路徑

BBFBBF發表於2018-06-19

修改Mariadb資料庫檔案儲存路徑

mysql也是類似的配置。
MariaDB預設的資料的儲存目錄為/var/lib/mysql,準備改為/data/mysql

停止服務

systemctl stop mariadb

資料遷移

mv /var/lib/mysql /data/mysql

修改配置

vim /etc/my.cnf

# 在[client-server]中新增
socket=/data/mysql/mysql.sock

# 在[mysqld]中新增,末尾必須是/
datadir=/data/mysql/

完整配置

#
# This group is read both both by the client and the server
# use it for options that affect everything
#
[client-server]
socket=/data/mysql/mysql.sock

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

[mysqld]
init_connect=`SET collation_connection = utf8mb4_unicode_ci`
init_connect=`SET NAMES utf8mb4`
character_set_server=utf8mb4
collation-server=utf8mb4_unicode_ci
skip-character-set-client-handshake=true
datadir=/data/mysql/

注:datadir上面的五行是設定預設字符集為utf8mb4,否則emoji表情是無法正確儲存的。

驗證

# 登入
mysql -uroot -p

# 查詢
show global variables like "%datadir%";

# 結果
MariaDB [(none)]> show global variables like "%datadir%";
+---------------+--------------+
| Variable_name | Value        |
+---------------+--------------+
| datadir       | /data/mysql/ |
+---------------+--------------+
1 row in set (0.00 sec)

相關文章