Pass MySQL database from one server to another via SSH


When you want to pass a MySQL database from one server to another and it is very heavy, I recommend doing it via SSH. To carry out this process we will use the “Putty” program and we need to have access to the SSH of the server.

The steps to follow are:

Dumpeating the DB to an SQL file
Pass the generated file to the new server
Import the SQL to the bd of the new server
Exporting database
On the server where we have the database, we execute via Putty the following command

1 mysqldump nombre_bd -u user_bd -p > archivo.sql

We are going to replace the code “db_name”, “user_bd” with the data of its database.

Passing SQL to the new server
Once the file is generated, file.sql, we have to pass it to the new server and we will use the “SCP” command

1 scp -P 22 -r archivo.sql user@server:/ruta

The number 22 determines the port where the SSH is going to connect, by default the “22” is used, but some companies for security change it, in case of connection error ask your company the port to connect to to the SSH.

In the separate command to replace the port for yours, you also have to replace “user” with your username, if you own the VPS it is usually “root” and the “server” for the ip or domain of your VPS and the “/ path” by the path where the SQL file will be saved on the new server.

Import SQL to the new database
We enter the new server, via putty, and execute the following command, before we have to create a clean database.

1 mysql nombre_bd -u user_bd -p < ruta/archivo.sql

In “/ path” we put the one that we put in the previous step, and replace “db_name” and “user_bd” by their respective data of the new server.

After carrying out these three simple steps, they already have their database successfully transferred.


Please enter your comment!
Please enter your name here