各位好,我的 CentOS 7 系統碟切分的很小,資料庫資料日益肥大快撐不住了,所以要更換資料儲存位置,參考了這一篇文章 How To Change a MariaDB Data Directory to a New Location on CentOS 7。
我先開了一台 Centos 7 的虛機做實驗,執行步驟如下:
service mariadb stop
mkdir /data/
rsync -avh /var/lib/mysql/ /data/
mv /var/lib/mysql /var/lib/mysql_bk
chown mysql:mysql -R /data
修改 /etc/my.cnf。
[mysqld]
datadir=/data/
socket=/data/mysql.sock
[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid
[client]
port=3306
socket=/data/mysql.sock
# include all files from the config directory
!includedir /etc/my.cnf.d
然後執行啟動。
service mariadb start
得到錯誤資訊。
Job for mariadb.service failed because the control process exited with error code. See "systemctl status mariadb.service" and "journalctl -xe" for details.
查看 mariadb.log 後得到。
230216 02:37:46 mysqld_safe Starting mysqld daemon with databases from /data/
230216 2:37:46 [Note] /usr/libexec/mysqld (mysqld 5.5.68-MariaDB) starting as process 6016 ...
230216 2:37:46 [Warning] Can't create test file /data/localhost.lower-test
230216 2:37:46 InnoDB: The InnoDB memory heap is disabled
230216 2:37:46 InnoDB: Mutexes and rw_locks use GCC atomic builtins
230216 2:37:46 InnoDB: Compressed tables use zlib 1.2.7
230216 2:37:46 InnoDB: Using Linux native AIO
230216 2:37:46 InnoDB: Initializing buffer pool, size = 128.0M
230216 2:37:46 InnoDB: Completed initialization of buffer pool
230216 2:37:46 InnoDB: Operating system error number 13 in a file operation.
InnoDB: The error means mysqld does not have the access rights to
InnoDB: the directory.
InnoDB: File name ./ibdata1
InnoDB: File operation call: 'open'.
InnoDB: Cannot continue operation.
230216 02:37:46 mysqld_safe mysqld from pid file /var/run/mariadb/mariadb.pid ended
即便我把 /data/
的權限設定為 777 都一樣得到沒有權限的資訊,不知道是哪邊出了問題。
你可以使用以下命令檢查 SELinux 是否啟用:
sestatus
如果 SELinux 為啟用狀態,則可以使用以下命令將 /data/ 目錄標記為可讀寫的:
chcon -Rv --type=mysql_db_t /data/
重新啟動 MariaDB:
systemctl start mariadb