Physical Address

304 North Cardinal St.
Dorchester Center, MA 02124

How to backup your Mysql Databases

Today we’ll look at how to backup your MySQL databases. It’s a good idea to backup your databases on a regular basis so ]you have a working ‘good’ copy in the event of data loss due to failure or if your website was compromised (read: hacked).

These commands are operating system independent and should work as long as mysqldump works on your operating system.

Single database backup

Let’s start off with backing up a single MySQL database:

mysqldump -u <username> -p<password> <databaseName> > <databaseName>-<date>.bkp.sql

Replace the placeholders, <>, with the relevant details and issue this command at shell. 

Note: There is no space between the password flag, -p, and the actual password. This is so that the command will run without needing asking you the password in the second prompt. You can the password, not the -p flag, and you’ll be asked for the password when you execute this.

Dump / Backup all databases

The following command will dump (backup) all the databases running in MySQL to a single file

mysqldump -u <username> -p<password> --all-databases > alldbs-<date>.sql

The same with this command, replace the placeholders and run at a shell prompt.

That’s it!