环境:
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'
解决方法:在/varllib/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模式
[root@data selinux]# getenforce
Enforcing
[root@data selinux]# setenforce 0
[root@data selinux]# getenforce
Permissive