MySQL database Backup Example

Home / MySQL database Backup Example

In this Post we will see how to take MySQL database backup using command line. First we have to login our MySQL using below command and enter password.

mysql -u vasu -p

Now to show all databases we use below command.

show databases

Now above command will show all the databases list that are present in your MySQL. Now it’s time to backup some database. So to take backup of any database we will use below syntax.

Syntax :
mysqldump -u {Mysql UserName} -p {databaseName} > {location where you want to save}\{Name What you want to give}.sql

mysqldump -u vasu -p myFirstDB > /usr/local/myFirstBackup.sql

After this command hit enter it will ask your Mysql Password Enter the password and you will successfully get the database backup.

Now After getting Backup we have to use it in mysql ,So for storing this backup in mysql we use the command source

Use the Following Syntax for restore database backup


source { location of database backup file }


source /usr/local/myFirstBackup.sql

If You want to get mysql database backup using cmd in windows then use following steps

First Go to to the bin folder of your mysql using the following path

  1. C:\Program Files\MySQL\MySQL Server 5.7\bin
  2. Now use ALT + D
  3. Now when address bar is highlighted, type cmd in the bar.
  4. Now Use the same command you use above
  5. mysqldump -u root -p yourdatabasename > c:/myfirstbackup.sql
  6. source C:\myFirstBackup.sql

Note : while you using cmd it might be possible that you get the Access is denied error, To resolve this open cmd  via Run as administrator , now use command it will work .

You may also like

How to create user in MySQL

Help Others, Please Share

About Author

Leave a Reply

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