MySQL : Transfer database from server to another server

In this article, I will show you how to dump a mysql database from one server to another remote server without having to export and import your SQL structure and data. We’ll dump a database directly to another empty database on another, remote server. In order to do this, you’ll need shell access to both servers and also create an empty database (with a valid login) on the remote server. Below is the command.

mysqldump -v -uxxxxx -pxxxxx database_name | ssh mysql -uxxxxx -pxxxxx database_name

So in the command above, we first execute a mysqldump to create an SQL dump of the current database. You’ll need to replace “xxxxx” with the actual username and password of the current database. Lastly, we specify the name of the database to dump.

Immediately, we connect to the remote server via SSH and execute a mysql command which will import the SQL dump which was just created, into the remote database. Same as with the current database, you’ll need to replace “xxxxx” with the username and password and of course the name of the remote database.

You will be prompted for password once the current database has been dumped. The password is the ROOT password for connecting to the remote server via SSH.

You’ll also notice that I used the “-v” option which executes the command in verbose mode. This prevents all the SQL code from being output in your terminal. It will just show a summary of the connection established, the tables dumped and then the disconnection from the  mysql server.

And that’s it! You’ve just transferred a database from one server to another.


  1. bright on November 24, 2008

    but were we can get shell access?

  2. Antonie Potgieter on November 25, 2008


    You can get shell access from your hosting/server provider. It is possible that the login details could be the same as your FTP details though. Give it a try. Something like this : ssh … and then enter the FTP password.

    All the best,

  3. Alex on June 16, 2009

    This is a fantastic tip and I thank you a lot man. I used to export, upload via FTP and all that mess. The last database was 200MB so finding your article has saved me a world of boredom. Thnx.

  4. Dipankar on July 20, 2009


    if my domain name is, then should I write the above command like this


    thank you

  5. Hospedagem de Sites on September 8, 2009

    I think the following link will help you….

  6. Rakesh Reddy on November 8, 2009

    Hello everyone i m trying to copy a databses’s of one server to another server(2 different systems n different server)in my project as a part of copy database wizard(.net platfrom)as i m in entry level(fresher)pls let me know the steps n code required to do this…..thanks in dvance

  7. Kirk on March 2, 2010

    Unless you receive errors during the transfer.

    ERROR at line 160 Got a packet bigger than ‘max_allowed_packet bytes.

    mysqldump: Got err no 32 on write.


    Of course there’s no indication of why these errors occur or how to get around them. So, I guess for those who were able to use this, congratulations. I’ll go back to phpMyAdmin import… It’s cumbersome, but it always works.

  8. Steve on May 6, 2010

    That’s a very good tip. Tried this with my site which is hosted by Yahoo! and it worked perfectly. There is a good yahoo web hosting review if you’re interested in switching.

  9. gate openers on September 16, 2010

    Can you show me some references to this? I want to know more information. Thanks

  10. Jill Han on September 27, 2010

    it was what I typed at command line
    mysql> mysqldump -v test | ssh mysql -uroot -prootpassword test;
    ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your
    MySQL server version for the right syntax to use near ‘mysqldump -v test | ssh mysql -uroot -prootpassword test’ at line 1

    any thoughts on what could cause that?

    thanks for your help,


  11. RB on October 25, 2010

    will this work for SQLServer as well?

  12. Junaid on October 29, 2010

    My wordpress database have crashed and my server is doing 100% cpu usage and it is creating a lot of headache for me.

    Is there a possibility to move the posts, categories, tags and users data to a new wordpress database?


  13. Nicolas on January 9, 2011

    Thank you so much man, an easy way to move mysql database to another server.


Leave a Reply

Your email address will not be published. Required fields are marked *

Pin It on Pinterest

Subscribe To Our Newsletter

Subscribe To Our Newsletter

Join our mailing list to receive the latest news and updates from our team.

You have Successfully Subscribed!

%d bloggers like this: