Forum archive
Change default MySQL database location
Hello,
I am using the Fileserver, TurnKey Linux 12.0 / Debian 6.0.5 Squeeze version.
I have installed mysql-server on this appliance which runs happily.
Due to space constraints on the server, I would like to change the default location of mysql databases (currently under /var/lib/mysql) to another directory, for example, to /srv/storage/mysqldb.
I have followed a number of tutorials to make this change, but every single time mysql fails to start with the changed configuration. If I go back to the default config, mysql fires up easily.
Is there a trick I should know about to do this? For example, Ubuntu has apparmor installed which prevents changes to mysql data location. Wondering if there is an equivalent of apparmor in Fileserver, such as SELinux (I could not find anything installed though)?
On the Fileserver appliance, try as I might I cannot make mysql start if I change the default location of its database.
Any help gratefully accepted!
Thanks,
doxford
NOTE: The following methods work for both Ubuntu Lucid LTS and Debian Squeeze versions of TurnKey FileServer. AppArmor seems disabled by default in the TKL version of Ubuntu, so no changes to AppArmor are needed
To change default location (/var/lib/mysql) of mysql databases using datadir in my.cnf (preferred method):
- /etc/init.d/mysql stop
- cd /var/lib/mysql
- ls -l (to check which databases are present in folder)
- mkdir /srv/storage/mysqldata
- chown -R mysql:mysql /srv/storage/mysqldata
- IMPORTANT: *Only* the databases need to be copied over to new location (i.e. do not copy over ib* files etc); therefore if we have 2 databases in /var/lib/mysql called 'mysql' and 'phpmyadmin' then we do:
- 'cp -r mysql /srv/storage/mysqldata/' and 'cp -r phpmyadmin /srv/storage/mysqldata/'
- chown -R mysql:mysql /srv/storage/mysqldata/*
- in /etc/mysql/my.cnf, *only* the 'datadir' line needs to be changed to: datadir = /srv/storage/mysqldata
- /etc/mysql/debian.cnf file should not be touched
- /etc/init.d/mysql start
To change default location (/var/lib/mysql) of mysql databases using mount-bind (alternative method):
- /etc/init.d/mysql stop
- mv /var/lib/mysql /var/lib/mysql_original (backup first for safety)
- mkdir /srv/storage/mysqldata
- cp -R /var/lib/mysql_original/* /srv/storage/mysqldata/
- mkdir /var/lib/mysql
- mount -o bind /srv/storage/mysqldata /var/lib/mysql
- chown -R mysql:mysql /var/lib/mysql
- /etc/init.d/mysql start