Moving the data dir for mysql in ubuntu 14.04

#Shutdown mysql
sudo service mysql stop

#change the data directory
sudo nano /etc/mysql/my.cnf

#Look for the “datadir” setting and set your new path
#Save the file after the changes are made

#update apparmor
nano /etc/apparmor.d/usr.sbin.mysqld

#Add to the end of the file
# NOTE: without the trailing slash “/” on /db/mysql/ you will get the dreaded error 13 permission denied error
# Also note that the path listed below was my path and sould be set to wherever you move your data directory to.

/db/mysql/ r,
/db/mysql/** rwk,

#Restart apparmor
sudo service apparmor restart

#then start up mysql
sudo service mysql start

#That should do it

#A quick test to verify it worked …
mysql -uYOUR_USERNAME -pYOUR_PASSWORD -e ‘show databases;’

#or if you dont want to put your password in a remembered command line
mysql -uYOUR_USERNAME -p -e ‘show databases;’