Changing MySql datadir in linux

Changing MySQL’s datadir where databases are stored is very simple. There is only 1 issue that is new and may drive you crazy.

In addition to changing permissions and altering my.cnf, you have to configure AppArmor:

1. create /home/mysql
2. chown -R mysql:mysql /home/mysql
3. cp /var/lib/mysql /home/mysql
4. edit /etc/my.cnf:

datadir = /home/mysql

5. configure apparmor at /etc/apparmor.d/usr.sbin.mysqld, adding the lines in bold and italics

#/var/lib/mysql/ r,
#/var/lib/mysql/** rwk,
/home/mysql/ r,
/home/mysql/** rwk,

6. restart apparmor and mysqld:

/etc/init.d/apparmor restart
/etc/init.d/mysqld stop
/etc/init.d/mysqld start

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s