How to Dump All MySQL Databases Easily?

If you wish to move your MySQL databases to a new server, it is important that you perform back up and restore all the databases in a proper way. MySQL has an easy method to dump all databases into an SQL file with just one command. The command works in all major OS such as Linux, Windows, Mac, etc.

Dump MySQL Databases Using mysqldump Command

Example

mysqldump -u root -p --all-databases > all_databases.sql

The above command will create an SQL file in the directory from where you executed the above command. You can use the SQL file to restore the databases to the new server.

Restore All Databases to The New Server

Example

mysql -u root -p < all_databases.sql

How to Create a Backup for a Single MySQL Database?

You can specify a database name in the command to create a backup of a single database.

mysqldump -u root -p db_name > db_name.sql

How to Restore a MySQL Database?

mysql -u root -p db_name < db_name.sql