Open the terminal
Stop MySQL with the command
Move existing data directory (which is located in /var/lib/mysql) to new dir /usr/new_datadir using the command
Create symlink from new dir to old one
Don’t change /etc/mysql/my.cnf
Ubuntu uses some security software called AppArmor that specifies the areas of your filesystem applications are allowed to access. Unless you modify the AppArmor profile for MySQL, you’ll never be able to restart MySQL with the new datadir location.
In the terminal, enter the command
Duplicate the lines beginning with /var/lib/mysql and replace duplicated strings with /usr/new_datadir
In my case it was:
………
……..
Restart the AppArmor profiles with the command
Restart MySQL with the command
MySQL should now start without any errors, have fun! See also article How to move the mysql datadir, Ubuntu change datadir issue
Theme by Danetsoft and Danang Probo Sayekti inspired by Maksimer