HiveBrain v1.2.0
Get Started
← Back to all entries
snippetsqlCritical

How can I move a database from one server to another?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
canmovedatabaseoneanotherhowserverfrom

Problem

How can I move MySQL tables from one physical server to another?

Such as this exact scenario:
I have a MySQL server that uses innodb table and is about 20GB size.

I want to move it to a new server, what's the most efficient way to do this?

Solution

My favorite way is to pipe a sqldump command to a sql command. You can do all databases or a specific one. So, for instance,

mysqldump -uuser -ppassword myDatabase | mysql -hremoteserver -uremoteuser -premoteserverpassword


You can do all databases with

mysqldump --all-databases -uuser -ppassword | mysql -hremoteserver -uremoteuser -premoteserver


The only problem is when the database is too big and the pipe collapses. In that case, you can do table by table or any of the other methods mentioned below.

Code Snippets

mysqldump -uuser -ppassword myDatabase | mysql -hremoteserver -uremoteuser -premoteserverpassword
mysqldump --all-databases -uuser -ppassword | mysql -hremoteserver -uremoteuser -premoteserver

Context

StackExchange Database Administrators Q#174, answer score: 101

Revisions (0)

No revisions yet.