close

這類的文章很多,
先介紹正常的步驟

1. 停止服務
sudo systemctl stop mariadb
2. 搬移資料(會將整個mysql目錄搬過去,含權限)
sudo rsync -av /var/lib/mysql /new_path
3. 修改my.cnf設定檔
[mysqld]
...
socket = /new_path/mysql/mysql.sock
datadir = /new_path/mysql
...
[client]
...
port=3306
socket = /new_path/mysql/mysql.sock
...

4. 修改Selinux (RHEL/Centos 才有, 使用getenforce檢查)
    4-1. 停用
           sudo vi /etc/sysconfig/selinux
           SELINUX=disabled

    4-2. 加入label ( What to Do if MariaDB Doesn't Start ),下面是官網的code
           semanage fcontext -a -t mysqld_db_t "/datadir(/.*)?"
           restorecon -Rv /datadir
           semanage fcontext -a -t mysqld_log_t "/var/log/mysql(/.*)?"
           restorecon -Rv /var/log/mysql

5. 啟動服務
sudo systemctl start mariadb
6.檢查
sudo mysql -u user -p -e "select @@datadir;"


但在啟動服務時,依然一直出現以下錯誤
Jul 27 16:23:52 systemd: Starting MariaDB database server...
Jul 27 16:23:52 mysqld: 2017-07-27 16:23:52 139628235921664 [Note] /usr/sbin/mysqld (mysqld 10.1.19-MariaDB) starting as process 25737 ...
Jul 27 16:23:52 mysqld: 2017-07-27 16:23:52 139628235921664 [Warning] Can't create test file /home/lib/mysql/XXXXXXXX.lower-test
Jul 27 16:23:52 mysqld: #007/usr/sbin/mysqld: Can't change dir to '/home/lib/mysql/' (Errcode: 13 "Permission denied")
Jul 27 16:23:52 mysqld: 2017-07-27 16:23:52 139628235921664 [ERROR] Aborting
Jul 27 16:23:52 systemd: mariadb.service: main process exited, code=exited, status=1/FAILURE
Jul 27 16:23:52 systemd: Failed to start MariaDB database server.
Jul 27 16:23:52 systemd: Unit mariadb.service entered failed state.
Jul 27 16:23:52 systemd: mariadb.service failed.

 

原來是因為新的路徑在home下,而MariaDB預設是有保護/home目錄的,

vi /usr/lib/systemd/system/mariadb.service 

ProtectHome=false

一切就正常了. MariaDB cannot start after update: [Warning] Can't create test file /home/mysql/beta.lower-test

 

參考

How to Change a Default MySQL/MariaDB Data Directory in Linux

arrow
arrow
    文章標籤
    change datadir mariadb
    全站熱搜
    創作者介紹
    創作者 abcg5 的頭像
    abcg5

    Aaron Yang

    abcg5 發表在 痞客邦 留言(0) 人氣()