Contact Us

Let us know to help you out quickly!

 Pritesh     Nov,30 2017

Backup and Restore MySQL DB using mysqldump command line tool

MySQL Workbench and there plenty of great GUI tool and allows you to work with various database related functionality including backup/restore but in a certain case, we may not able to use GUI tool. For an example, Need to perform operation command line server or to make automation like sync my production database to test database before performing test via automation tool)


Recently I required copying production database on MySQL server to staging server database and I do not want it to copy entire 100 GB database to my local server and upload it again as this will be very time-consuming. A better option will be I can somehow take backup of Ubuntu Server and restore it back to a Staging Server which is pretty faster option to work with.


mysqldump is command line tool come with MySQL Client ToolSet which is used by all GUI tool as well for backup database. 


Use Case #1:

Copying database on different server but having the same name.

Backup from source DB

--databases will make sure to add "USE [dbname]" in export so it you may not required to choose database while restoring.

Restore on destination db

Above command will restore it on database with same name.


Use Case #2:

Copying database on probably same DB server but with a different name.

Note: No --databases option which will make sure it WON'T add "USE [dbname]" in export.

Restore on destination db

You may need to specify database name in which like to restore if exported without --databases option and this will allow you to restore with different name.