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:
- Stop the mysql server
service mysql stop
-
Edit the file
/etc/mysql/mysql.conf.d/mysqld.cnf
and edit thedatadir
field to point to new location.For example
datadir = /data/mysql
-
Then copy the content of
/var/lib/mysql
to new location:cp -pr /var/lib/mysql /data
-
Then edit the
/etc/apparmor.d/usr.sbin.mysqld
file. Remove/var/lib/mysql
and add the newdatadir
location. In my case it is# Allow data dir access /data/mysql/ r, /data/mysql/** rwk,
Restart apparmor service
systemctl restart apparmor
-
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
sudo service apparmor status
- If it is not active, use
journalctl -xe
, and verify which profile has problems.