Stop MySQL using the following command:
sudo /etc/init.d/mysql stopCopy the existing data directory (default located in
/var/lib/mysql) using the following command:sudo cp -R -p /var/lib/mysql /newpathedit the MySQL configuration file with the following command:
sudo gedit /etc/mysql/my.cnfLook for the entry for
datadir, and change the path (which should be/var/lib/mysql) to the new data directory.In the terminal, enter the command:
sudo gedit /etc/apparmor.d/usr.sbin.mysqldLook for lines beginning with
/var/lib/mysql. Change/var/lib/mysqlin the lines with the new path.Save and close the file.
Restart the AppArmor profiles with the command:
sudo /etc/init.d/apparmor reloadRestart MySQL with the command:
sudo /etc/init.d/mysql restartNow login to MySQL and you can access the same databases you had before.