修改 my.cnf

datadir=/www/mysql/data
socket=/www/mysql/data/mysql.sock

其实这里不需要复制/var/lib/mysql下的文件到新目录,修改完配置之后,mysql会自动复制/var/lib/mysql下的文件到新目录

关闭SELinux

vim /etc/selinux/config #编辑文件
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
#permissive - SELinux prints warnings instead of enforcing.
#disabled - No SELinux policy is loaded.
SELINUX=enforcing
# SELINUXTYPE= can take one of these two values:
# targeted - Targeted processes are protected,
# mls - Multi Level Security protection.

将SELINUX=enforceing 改为 SELINUX=disabled 重启机器就ok了

最后

ln -s /www/mysql/data/mysql.sock /var/lib/mysql/mysql.sock