- Current disk is out of space
- Current partition is out of space
- There is a better filesystem to improve disk IO performance.
Thursday, November 22, 2012
Change MySQL database directory
Why do I need to change MySQL database directory or location?
Steps to do this on Centos 6 with SELinux enforced.
Step 1: Stop MySQL server
Step 2: Create the new directory
A new directory can be created in the new disk or partition.
Step 3: Copy existing database to new location
mv /var/lib/mysql/* /srv/mysql/
Step 4: Configure MySQL server
Edit /etc/my.cnf with following
Save and close the file.
5. Configure SELinux to allow new database
View current settings
ls -lZ /var/lib/mysql
Edit settings with e.g.
semanage fcontext -a -t mysqld_db_t "/media/server/mysql(/.*)?"
chcon -R -t mysqld_db_t /media/server/mysql
restorecon -Rv /media/server/mysql
Check settings are in the config file
grep -i mysql /etc/selinux/targeted/contexts/files/file_contexts.local
6. Start up MySQL
I had to reboot the server and change selinux to permissive for all this to work.