How to Backup and Restore MySQL Databases From Command Line?

mysqldump is an easy and quick tool to create backup of MySQL databases. It creates a dump file of MySQL databases containing SQL commands to recreate the database at the destination MySQL server. mysqldump allows you to backup a single database and multiple databases as well.

Take MySQL Database Backup


To take backup of MySQL database, first you'll have to connect to MySQL server through command line.

mysql -uusername -p // Replace username with your username.

Enter MySQL user password and hit Enter. You will see mysql prompt appears. To take backup of MySQL database, first you must know the database name you wish to backup. You can display all databases by firing following command at the mysql prompt.

show databases;

Now, assume that you want to take backup of database named mysql-database.

mysqldump mysql-database > mysql-database-backup.sql

This command will backup database mysql-database into a SQL dump namely mysql-database-backup.sql.

mysqldump --databases mysql-database-one mysql-database-two mysql-database-three > database-backups.sql

This command will backup databases mysql-database-one, mysql-database-two and mysql-database-three into a SQL dump file namely database-backups.sql.

Restore MySQL Database

To restore a MySQL database from a backup file, fire following command.

mysql mysql-database < mysql-database-backup.sql

Here, mysql-database is the name of database you want to restore and mysql-database-backup.sql is the backup file to be restored.
  • 0 Users Found This Useful

Was this answer helpful?

Related Articles

Fix :: Unable to login at phpMyadmin after revoking MySQL root user

Problem Statement I am not able to login into phpMyadmin after revoking root user. Solution...

How do I connect to a MySQL database with MySQL Workbench?

MySQL Workbench is the excellent MySQL client tool used to connect to remote MySQL database from...

How to Administrate MySQL Server with mysqladmin commands?

By using mysqladmin commands, you can perform basic MySQL tasks very easily, such as...

How to fix InnoDB database corruption?

Check the log files. If you find InnoDB database corruption, follow the below mentioned steps:...

How to Fix MySQL Error "Plugin 'InnoDB' registration as a STORAGE ENGINE failed"?

Problem Statement MySQL service is stopped. Error Message 150206 4:42:12 [ERROR] Plugin...