For example, change mysql data directory from /var/lib/mysql to /var/data/mysql
Step1: Copy the /var/lib/mysql to new name /var/lib/mysqlnew
cp -prvf /var/lib/mysql /var/lib/mysqlnew
sudo vi /etc/mysql/my.cnf
Looking for:
datadir = /var/lib/mysql
Change to :
datadir = /var/data/mysql
And open file:
sudo vi /etc/apparmor.d/usr.sbin.mysqld
Looking for:
/var/lib/mysql/ r,
/var/lib/mysql/** rwk,
Change to:
/var/data/mysql/ r,
/var/data/mysql/** rwk,
Reload AppArmor profile:
sudo /etc/init.d/apparmor reload
Finally, restart MYSQL:
sudo /etc/init.d/mysql restart