Moving MySQL datafiles

database
ID: 20150520 ACCESSING DATA...
SYSTEM: ARCHIVE FILE: MOVING MYSQL DATAFILES STATUS: ACTIVE

In this article, I’ll demonstrate multiple solutions to move datafiles

Stop the Mysql instance.

/etc/init.d/mysql stop

Then move the files and put symbolic links to lure Mysql into thinking the files are still in place.

mkdir /new_dir/datafiles/my_db
cd /old_dir/datafiles/
cp -Rvp my_db/* /new_dir/datafiles/my_db/.
rm my_db/* && rmdir my_db/
ln -s /new_dir/datafiles/my_db/ my_db

Method 2: changing the configuration file

Open your Mysql configuration file: /etc/mysql/my.cnf and look for the entry for “datadir”. Then, simply change the path (which should be “/var/lib/mysql”) to the new data directory.

This method also requires an instance restart.

sudo /etc/init.d/mysql restart

Tags: