修改mysql的datadir目录

1.停止mysql

1
sudo /etc/init.d/mysql stop

2.复制/var/lib/mysql目录到指定的路径

1
sudo cp -R -p /var/lib/mysql /data/mysql

3.修改mysql配置文件my.cnf:

1
2
datadir=/data/mysql
socket=/data/mysql/mysql.sock

4.修改apparmor

1
sudo vim /etc/apparmor.d/usr.sbin.mysqld

将/var/lib/mysql路径替换为/data/mysql

1
2
3
4
#/var/lib/mysql/ r,
#/var/lib/mysql/** rwk,
/data/mysql/ r,
/data/mysql/** rwk,

5.重启

1
2
sudo /etc/init.d/apparmor restart
sudo /etc/init.d/mysql restart

from:
1.How to change MySQL data directory?
2.Linux Ubuntu change datadir / database location dir in 5 minutes Move mysql database to other path