Home » Categories » Multiple Categories

How To Migrate a MySQL Database Between Two Servers

Transferring a database between virtual private servers can be accomplished using a SCP (Secure Copy), a method of copying files derived from the SSH Shell. Keep in mind, you will need to know the passwords for both virtual servers.

In order to migrate the database, there are two steps:

Step One—Perform a MySQL Dump

Before transferring the database file to the new VPS, we first need to back it up on the original virtual server by using the mysqldump command.
mysqldump -u root -p --opt [database name] > [database name].sql
After the dump is performed, you are ready to transfer the database.

Step Two—Copy the Database

SCP helps you copy the database. If you used the previous command, you exported your database to your home folder.

The SCP command has the following syntax:
scp [database name].sql [username]@[servername]:path/to/database/
A sample transfer might look like this:
scp newdatabase.sql [email protected]:~/
After you connect, the database will be transferred to the new virtual private server.

Step Three—Import the Database

Once the data has been transferred to the new server, you can import the database into MySQL:
 mysql -u root -p newdatabase < /path/to/newdatabase.sql
With that, your transfer via SCP will be complete.
Attachments Attachments
There are no attachments for this article.
Related Articles RSS Feed
How To Install Linux, Nginx, MySQL, PHP (LEMP) Stack on Debian 7
Viewed 4137 times since Fri, Dec 27, 2013
How To Install an Upstream Version of Node.js on Ubuntu 12.04
Viewed 2887 times since Sun, Dec 29, 2013
How To Use Dokku Plugins to Access Additional Functionality
Viewed 4934 times since Sun, Dec 29, 2013
How to Setup and Configure an OpenVPN Server on Debian 6
Viewed 2716 times since Thu, Dec 26, 2013
How To Set Up a Postfix Email Server with Dovecot: Dynamic Maildirs and LMTP
Viewed 3885 times since Mon, Dec 30, 2013
How To Write a Linux Daemon with Node.js
Viewed 10510 times since Sun, Dec 29, 2013
How To Install And Run A Node.js App On Centos 6.4 64bit
Viewed 10713 times since Sun, Dec 29, 2013
How To Install and Use PostgreSQL on Ubuntu 12.04
Viewed 6547 times since Mon, Dec 30, 2013
How To Install Wordpress on Arch Linux
Viewed 2839 times since Sun, Dec 29, 2013