• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 299
  • Last Modified:

Move MySQL Databse from Command Line

I have full root command-line access to Server A and Server B.  Both servers are running Linux (CentOS 5).

I have a MySQL database on Server A that is more than 20 gig in size.

How can I move it from a command line to server B?
3 Solutions
its really straight forward  follow the guide below


to copy the database to the new server you can use scp

or ftp or whichever file transfer you want to use

could also use winscp if connecting to the servers from a windows machine

Backup the current database by running
"mysqldump -u mydatabaseuser -p mydatabase > backup.sql"

Since your file will be quite big you should use gzip to compress it before copying it over to the new server.
"gzip backup.sql"

Unzip the compressed file on the new server
"gunzip bckup.sql.gz"

Then create the new database that you wish to import the backup into and then run
"mysql -u mydatabaseuser2 -p mydatabase2 < backup.sql"

Hope this helps

another way of doing this is to use rsync over ssh if you have those technologies in place already.  I currently use this same setup for backing up my databases.  You have to be careful as rsync will copy a table file even if it is currently being updated.  In other words, you could get partial or incomplete tables.  I would suggest shutting down the database if you decide to use this method of transfer.

Below is the command line that you will want to use:


Once the transfer is complete, restart Server B's mysql instance.  You should then see your tables with data in them after loggin into that Database.

For more information on the switches for rsync, run "man rsync"

Hope this helps.  I would suggest that you do it as mentioned above as it is mysql's recommended method of backing up/moving databases.  But if you are comfortable with shutting the DB down till the above command completes I would use this method.    
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now