How to take a Backup and Restore of MySQL Databases via Command Line?

mysqldump is an easy and quick tool to create a 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. Are you looking to take the MySQL database using the cron? Please refer to take MySQL database using cron for more details.

Take MySQL Database Backup


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

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


Enter MySQL user password and hit Enter. You will see a 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 the following command at the MySQL prompt.

show databases;


Now, assume that you want to take a backup of the 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 the following command.

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


Here, mysql-database is the name of the database you want to restore and mysql-database-backup.sql is the backup file to be restored.

Related Articles

How to back up MySQL databases using AutoMySQLBackup?

What is AutoMySQLBackup? AutoMySQLBackup is a script that allows you to schedule the automatic...

How to edit the my.cnf file of MySQL in Linux VPS?

Linux VPS and Dedicated server customers can edit MySQL configuration settings by modifying...

How to rename MySQL Database from cPanel?

cPanel offers MySQL Database rename option. Renaming MySQL Database requires while migrating...

How to check MYSQL Database size in phpMyAdmin and via command?

Sometimes it is required to check the MySQL Database size. You can check it from the phpMyAdmin...

How to connect MySQL using Python?

There are several ways to use python to connect with the MySQL database. In this article, we will...

  • 0 Users Found This Useful

Was this answer helpful?