logo
InternetCopy MySQL Database from One Server to Another

Four Steps to Copy MySQL Database from One Server to Another

By Sophia | Last Updated

Do you want to upgrade your server? You might think it is a difficult thing to migrate the old server database include configuration information and user profiles to a new server without data loss. Actually, copying MySQL database from one server to another requires only four steps in total.

How to Copy Mysql Database to Another Server Using Command

The following tutorial will show you how to export MySQL database from the old server, safeguard it, copy and import it to the new server then make sure it is there.

Notes

  • 1. Please make sure there is the same version of MySQL running on two servers with the same contribution.
  • 2. Execute the –single-transaction flag to avoid database lock during the data exporting.

Step 1: Exporting MySQL using mysqldump utility

The Oracle built-in tool called mysqldump allows users to export database to a dump file. Before running the command, please replace the [database name] with your own name.

mysqldump -u root -p --opt [database name][database name].sql

Now your dump file is performed.

Step 2: Encrypt the backup file

To prevent your database from attack from the virus, we can use the zip command to secure it.

zip --encrypt dump.zip db.sql

Type your password when a prompt show you. Then you can see the dump file is encrypted.

Step 3: Transfer the backup file to the new server

The SCP can help you transfer the encrypted dump file to the new server.

scp /path/to/source-file user@host:/path/to/destination-folder/

Step 4: Import database to the new server

To unencrypt and extract the dump file, run this command:

unzip -P your-password dump.zip

After extract the file, you can import to the new server:

mysql -u root -p newdatabase < /path/to/newdatabase.sql

Related Articles: