[HOW-TO] Back up all MySQL databases

To backup all or some of your MySQL databases, you’ll need mysqldump which comes bundled with mysql. If you have MySQL installed, you probably have mysqldump installed already.

To backup all databases use the following command:

In linux:

mysqldump -uroot -ppassword --all-databases | gzip > /media/disk-2/db.sql.gz

In Windows:

mysqldump -uroot -ppassword --all-databases > db.sql

This will backup all your databases from a single command.

To backup just a selected few use the following command:

In linux:

mysqldump -uroot -ppassword --databases db1 db2 | gzip > db1db2.sql.gz

In windows:

mysqldump -uroot -ppassword --databases db1 db2 > db1db2.sql

Replace db1 and db2 with your database names. You can add more databases separated by a space.

Replace ‘root’ and ‘password’ with your own mysql username and password.

Note that there is no space between ‘u’ and ‘root’ in -uroot, and between ‘p’ and ‘password’ in -ppassword

For more options please check out its man page if you are on linux or mysqldump --help which is available both in linux and windows.

It can’t get any simpler than that.


Leave a comment

Your email address will not be published.