Apparmor error after mysql folder relocation

I followed the following steps to change the default data directory in mysql:

I have the configuration of the system as follows

mysql Ver 14.14 Distrib 5.7.19

Ubuntu 16.04 LTS

The steps are as follows:

  1. Stop the mysql server service mysql stop
  2. Edit the file /etc/mysql/mysql.conf.d/mysqld.cnf and edit the datadir field to point to new location.

    For example datadir = /data/mysql

  3. Then copy the content of /var/lib/mysql to new location:

    cp -pr /var/lib/mysql /data
    
  4. Then edit the /etc/apparmor.d/usr.sbin.mysqld file. Remove /var/lib/mysql and add the new datadir location. In my case it is

     # Allow data dir access
     /data/mysql/ r,
     /data/mysql/** rwk,
    
  5. Restart apparmor service systemctl restart apparmor

  6. Restart the mysql service service mysql start

    The above steps worked for me, I hope it will work for you too.


Always check the Apparmor status

  1. sudo service apparmor status
  2. If it is not active, use journalctl -xe, and verify which profile has problems.