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 (LEMP) nginx, MySQL, PHP stack on Arch Linux
Viewed 14054 times since Sun, Dec 29, 2013
How To Install Opigno on Debian 7 with Git and Drush
Viewed 4310 times since Sat, Jan 4, 2014
How To Use CakePHP to Create a Small Web Application
Viewed 3486 times since Fri, Jan 3, 2014
How to Install Piwik on an Ubuntu 12.04 Cloud Server
Viewed 3607 times since Sat, Jan 4, 2014
The Basics of Using the Sed Stream Editor to Manipulate Text in Linux
Viewed 6894 times since Fri, Dec 27, 2013
How To Use Traceroute and MTR to Diagnose Network Issues
Viewed 7095 times since Fri, Dec 27, 2013
How To Use Dokku Plugins to Access Additional Functionality
Viewed 5061 times since Sun, Dec 29, 2013
How to Add a Swap File on an Arch Linux Cloud Server
Viewed 3139 times since Fri, Dec 27, 2013
How To Perform Basic Queries in MySQL and MariaDB on a Cloud Server
Viewed 2662 times since Thu, Jan 2, 2014
How To Use Yaourt to Easily Download Arch Linux Community Packages
Viewed 4540 times since Fri, Dec 27, 2013