Moving Mysql database data directories to new partition

If you need to move a mysql database’s data files to another partition because space on /var/lib/mysql is getting low you can do this:

1) Shut down the database

service mysqld stop

2) move the database files using cpdir

cd /var/lib/mysql/databasename
find . -depth -mount -print | cpio -pdmv /NEWPARTITION/mysql/databasename

3) Rename the old directory
4) Create a symbolic link between old and new directory

5) Fix context (SE linux Permissions) on the new directory has good SELINUX permissions.

chcon -R -u system_u -r object_r -t mysqld_db_t /NEWPART/mysql

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published.