参考https://www.cnblogs.com/panchanggui/p/9888248.html

1停服务

/etc/init.d/mysqld stop

ls /var/lib/mysql/

2改配置

vi /etc/my.cnf

datadir=/data/mysql

3移数据

rsync -a /var/lib/mysql /data

hown -R mysql:mysql /data

4启动

/etc/init.d/mysqld start 

#启动失败报错如下

200303 10:37:11 mysqld_safe Starting mysqld daemon with databases from /data/mysql

200303 10:37:11 [Warning] Can't create test file /data/mysql/logserver2.lower-test

200303 10:37:11 [Warning] Can't create test file /data/mysql/logserver2.lower-test

/usr/libexec/mysqld: Can't change dir to '/data/mysql/' (Errcode: 13)

200303 10:37:11 [ERROR] Aborting

200303 10:37:11 [Note] /usr/libexec/mysqld: Shutdown complete

200303 10:37:11 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended

改selinux配置恢复正常

参考https://www.jb51.net/article/61107.htm

getenforce

setenforce 0

vi /etc/selinux/config