Creating a copy of a MySQL database server

If you need to create an exact copy of your MySQL server. You first need to install the MySQL software on the new server, make sure this is exactly the same version, same compile time settings an /etc/my.cnf file.

Next make sure that no other clients are writing to the database, for example turn off any web applications etc..

You will then need to use the mysqldump utility to create a SQL dump file, transfer it to the new server and insert into into the new MySQL server using the mysql CLI.

MySQL v4.0 dump command on the old server:

mysqldump --allow-keywords --all --add-drop-table --add-locks --disable-keys --extended-insert -A -u root -p > /tmp/databases.sql

MySQL restore command on the new server:

mysql -u root -p < /tmp/databases.sql

Last updated: 11/11/2006