How to migration the mysql’s databases directory to other device

By December 12, 2016Tutorials

Tips: Make sure the system don’t running any work to do commands as follow.

Because of the large number of records caused by growing for databases,will take up a lot of hard disk space,so we should mount other devices to the local server, migrate the database directory to the mounted path, and then connect the directory to the server’s original location.

1、Stop the mysql server from the asterCC server

Login the CentOS system,view the mysql server is running as follows:
service mysqld status

Forexample:

selection_093

Make sure the system don’t running any work to do commands as follow:
service mysqld stop

Forexample:

selection_094

After stop mysql server please view the mysql server whether already stop.

2、The original database directory is backed up before the migration

Mount other device for asterCC server, forexample the /mnt directory or other directory from centos.

Migration the /var/lib/mysql directory copy to /mnt directory,as follows:
cp -Rp /var/lib/mysql /mnt

Forexample:

selection_095

Because of the databases is very lurge, please wait this command for some time.

The directory /var/lib/mysql,rename as mysql.bak, as follows:
mv /var/lib/mysql /var/lib/mysql.bak

Forexample:

selection_096

3、Link the new database directory to the original directory location

After copy the mysql directory,link the new database directory to the original directory /vra/lib, as follows:

ln -s /mnt/mysql /var/lib

Forexample:

selection_097

4、Start the mysql server

Strat the mysql server:
service mysqld start

Forexample:

selection_098

At this point you can view the status of the command to see whether the mysql is running,make sure can loginthe mysql system, view the call records for verification.
After all operations have been confirmed to be successful, you can delete the original data directory mysql.bak backup file to save the server space.

Leave a Reply