NFS服务器:
iptables -X
iptables -F
yum -y install nfs-utils rpcbind
groupadd -g 27 mysql
useradd -u 27 -g mysql mysql
mkdir /home/sharednfs
chmod a+x /home/sharednfs
chown -R mysql:mysql home/sharednfs
setfacl -m u:mysql:rwx /home/sharednfs
vim /etc/exports
/home/sharednfs *(rw,all_squash,anonuid=27,anongid=27)

systemctl restart nfs
systemctl enable rpcbind.service
systemctl enable nfs-server.service

nfs客户端(mysql服务器)
iptables -X
iptables -F
apt-get install nfs-common
yum install nfs-utils -y
/etc/init.d/rpcbind start
mkdir /var/lib/mysqlnfs
mount -t nfs 192.168.31.207:/home/sharednfs /var/lib/mysqlnfs
或者 mount -t nfs 192.168.31.207:/sharednfs /var/lib/mysqlnfs
showmount -e 127.0.0.1

vi /etc/fstab
添加: 192.168.31.207:/home/sharednfs /var/lib/mysqlnfs nfs defaults 0 0

安装mysql
yum install wget -y
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
rpm -ivh mysql-community-release-el7-5.noarch.rpm
yum list
yum install mysql mysql-server mysql-client mysql-devel -y

修改mysql的datadir
systemctl stop mysqld
cp -rp /var/lib/mysql/ /var/lib/mysqlnfs
修改my.cnf 的路径
datadir=/var/lib/mysqlnfs
socket=/var/lib/mysqlnfs/mysql.sock
pid-file=/var/lib/mysqlnfs/mysqld.pid

一般my.cnf包含以下:
[mysqld]
datadir=/var/lib/mysqlnfs
socket=/var/lib/mysqlnfs/mysql.sock
[client]
default-character-set=utf8
socket=/var/lib/mysqlnfs/mysql.sock
[mysqld_safe]
err-log=/var/log/mysqld.log
pid-file=/var/lib/mysqlnfs/mysqld.pid

sock可以不修改,如果一定要修改,可能会导致sock的信息不对,而改了root的密码,
解决办法:ln -s /var/lib/mysqlnfs/mysql.sock /var/lib/mysql/
systemctl start mysqld
systemctl start rpcbind
systemctl start nfs
如果启动不了mysql就备份数据,然后初始化mysql
/usr/bin/mysql_install_db --user=mysql
systemctl stop mysqld
/usr/bin/mysqld_safe --skip-grant-tables &
mysql -uroot -p
use mysql;
update user set password=password('123') where user='root'; 旧版
update mysql.user set authentication_string=password('root') where user='root' ; 新版
flush privileges;
exit;
如果启动mysql一直提示 Can’t connect to local MySQL server through socket
请编辑 /etc/my.cnf添加client
[client]
default-character-set=utf8
socket=/var/lib/mysqlnfs/mysql.sock