1. 程式人生 > >CentOS伺服器mysql更改儲存路徑及可能出現的問題

CentOS伺服器mysql更改儲存路徑及可能出現的問題

環境:

CentOS:5.11     mysql-server:5.0.95

1.停止mysql服務程序

service mysqld stop

2.拷貝資料

cp -rp /var/lib/mysql 目標路徑

3.修改/etc/my.cnf

將datadir和socket改成新的路徑

#datadir=/var/lib/mysql

datadir=/mnt/sdb1/mysql

#socket=/var/lib/mysql/mysql/sock

socket=/mnt/sdb1/mysql/mysql.sock

4.修改mysql啟動指令碼/etc/init.d/mysqld

將datadir改成新的路徑

5.重新啟動mysql服務

出現的問題:

1.伺服器登入mysql報Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'

解決方法:在/var/llib/mysql下建立軟連結(該方法同樣也能解決其他呼叫mysql資料庫服務的類似程式報錯)

ln -s /mnt/sdb1/mysql/mysql.sock /var/lib/mysql/mysql.sock

2.mysqld服務啟動失敗 /var/log/mysqld.log報錯:

160523 12:58:03  mysqld started
160523 12:58:03 [Warning] Can't create test file /mnt/sdb1/mysql/localhost.lower                                                                                        -test
160523 12:58:03 [Warning] Can't create test file /mnt/sdb1/mysql/localhost.lower                                                                                        -test
/usr/libexec/mysqld: Can't change dir to '/mnt/sdb1/mysql/' (Errcode: 13)
160523 12:58:03 [ERROR] Aborting

160523 12:58:03 [Note] /usr/libexec/mysqld: Shutdown complete
解決方法:關閉selinux或者將selinux的訪問許可權設定為permissive模式
[[email protected] selinux]# getenforce
Enforcing
[[email protected] selinux]# setenforce 0
[[email protected] selinux]# getenforce
Permissive

參考: