Change MySQL Data Directory

Stop MySQL service

service mysql stop

Backup existing MySQL data directory

tar -cvf mysql.tar /var/lib/mysql

Create a new data directory with proper permissions

mkdir -p /data/mysql
chown mysql:mysql /data/mysql

Migrate existing data into the new location using rsync command

nohup rsync -avp /var/lib/mysql/ /data/mysql

Change data directory in /etc/mysql/my.cnf as follows

datadir = /data/mysql

Change AppArmor data directory paths under /etc/apparmor.d/usr.sbin.mysqld

# Replace the lines beginning with /var/lib/mysql into /data/mysql
:%s/\/var\/lib\/mysql/\/data\/mysql/g

Start MySQL service

service mysql start