关闭服务器防火墙,关闭服务器Selinux  临时关闭可以用 setenforce 0

MySQL默认使用的用户为 mysql 组也为mysql

可以在/etc/passwd  与/etc/group中看到   uid与gid都为27  所以需要在NFS的服务端加入账户并授权


[root@www ~]# groupadd -g 27 mysql

[root@www ~]# useradd -u 27 -g mysql mysql

[root@www ~]# mkdir /home/sharednfs

[root@www ~]# setfacl -m u:mysql:rwx /home/sharednfs

[root@www ~]# vim /etc/exports

/home/sharednfs *(rw,all_squash,anonuid=27,anongid=27)


重启服务器端nfs

systemctl restart nfs


客户端服务器MySQL配置文件,把data目录改为nfs挂载的目录上,重启MySQL即可。

[mysqld]

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

datadir=/home/sharedisk/mysql
socket=/home/sharedisk/mysql/mysql.sock

character-set-server=utf8
lower_case_table_names=1
slow_query_log=1
long_query_time=10.000000

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

[client]
socket=/home/sharedisk/mysql/mysql.sock