MySQL - How to copy MySQL database to another server?
Using mysqldump:
You can copy a single database, one by one:
mysqldump -h <server1> -u <user1> -p<password1> old_db | mysql -h <server2> -u <user2> -p<password2> target_db
Or split the command if you don’t want to expose your password in plaintext:
mysqldump -h <server1> -u <user1> -p db1 | mysql -h <server2> -u <user2> -p db2
Run the command then enter two passwords.
To copy all databases from the current server at once:
mysqldump -h <server1> -u <user1> -p<password1> --all-databases | mysql -h <server2> -u <user2> -p<password2>
Using TablePlus GUI Tool
Backup
- From the welcome screen, choose
Backup
- Choose your connection and database
- Hit
Start backup
Then TablePlus will generate a dump file to save on your computer.
Restore
- From the welcome screen, choose
Restore
- Choose your connection
- Choose an existing database or choose to create a new one
- Hit
Start restore
- Choose the dump file you just generated and start restoring.
All done!
Need a good GUI Tool for MySQL? TablePlus is a modern, native tool with an elegant UI that allows you to simultaneously manage multiple databases such as MySQL, PostgreSQL, SQLite, Microsoft SQL Server and more.
Not on Mac? Download TablePlus for Windows.
On Linux? Download TablePlus for Linux
Need a quick edit on the go? Download TablePlus for iOS.