Make MySql data portable, adjusting AppArmor

Posted under » MySQL » Ubuntu on 2 December 2010

To make mysql portable, you should be able to put the data in a place convenient for backup using rsync for eg.

However, for security consideration, its best to just keep the data at "/var/lib/mysql". After all, that is why AppArmor is for. You can rsync your data directly there.

First stop mysql.

Copy the existing data directory

cp -R -p /var/lib/mysql /path/to/new/datadir

Edit the MySQL configuration file

gksu gedit /etc/mysql/my.cnf

Ubuntu uses some security software called AppArmor that specifies the areas of your filesystem applications are allowed to access. Unless you modify the AppArmor profile for MySQL, you’ll never be able to restart MySQL with the new datadir location.

gedit /etc/apparmor.d/usr.sbin.mysqld

Restart the AppArmor profiles

/etc/init.d/apparmor reload

Restart MySQL

more info. >

To confirm that mysql is indeed running from the new directory, go to phpmyadmin > variables.

It can get more complicated if the data is to be used on another system or setup. It is important that you have the same version of MySQL.

Rsync to another computer often result with the wrong ownership or group. If the mysql won't run or "file is in use" error, you need to ensure the owner and group is "mysql".

web security linux ubuntu GIT svn Raspberry apache mysql php drupal cake symfony javascript Ajax css