Centos 通过yum安装(RPM分发进行安装)MySQL的几个人默认目录如下:
假如要把目录移到/home/data下需要进行下面几步:
1、home目录下建立data目录
mkdir -p /home/data & cd /home/data/
2、把MySQL服务进程停掉
[root@localhost data]# mysqladmin -u root -p shutdown
Enter password:
3、把/var/lib/mysql整个目录移到/home/data
mv /var/lib/mysql /home/data/
或者
cp -R /var/lib/mysql /home/data/
4、设置/home/data/下mysql文件夹的属主和权限
chown -R mysql:mysql /home/data/mysql
[root@localhost data]# ls
mysql
[root@localhost data]# ll
drwxr-x--x. 5 root root 4096 10月 31 04:03 mysql
[root@localhost data]# chown -R mysql:mysql /home/data/mysql
[root@localhost data]# ll
drwxr-x--x. 5 mysql mysql 4096 10月 31 04:03 mysql
5、修改配置文件/etc/my.cnf
为保证MySQL能够正常工作,需要指明mysql.sock文件的产生位置。修改socket=/var/lib/mysql/mysql.sock一行中等号右边的值为:/home/data/mysql/mysql.sock 以及修改datadir为/home/data/mysql操作如下:
#datadir=/var/lib/mysql
datadir=/home/data/mysql
#socket=/var/lib/mysql/mysql.sock
socket=/home/data/mysql/mysql.sock
6、重新启动MySQL服务
service mysqld start
往往坑总是一个接着一个。
以上截图看不到任何问题,我们来查看一下日志
tail -n 1000 /var/log/mysqld.log -f
2017-10-31T08:48:06.533321Z 0 [Warning] Can't create test file /home/data/mysql/localhost.lower-test
2017-10-31T08:48:06.533401Z 0 [Note] /usr/sbin/mysqld (mysqld 5.7.20) starting as process 25325 ...
2017-10-31T08:48:06.536585Z 0 [Warning] Can't create test file /home/data/mysql/localhost.lower-test
2017-10-31T08:48:06.536617Z 0 [Warning] Can't create test file /home/data/mysql/localhost.lower-test
设置一个SELinux即可
setenforce 0