OK Here’s a quick one. We’ve all been there we have a MySQL Database and need to back it up quickly on the command line.

The command for this is mysqldump [options] [database] [file_to_dump_database]. The options we’re interested in are:


  • -u (the user)
  • -p (the users password
  • –databases (list of databases to dump, separated by a space)
  • –all-databases (dumps every database)

To back-up

So to backup the wordpress database we would use: mysqldump -u[user] -p[user_password] wordpress > wordpress.sql

To back-up more than one, say wordpress and joomla: mysqldump -u[user] -p[user_password] --databases wordpress joomla > databases.sql

To back-up all databases you will need to be root so: mysqldump -uroot -p[root_password] --all-databases > alldatabases.sql

To restore all

To restore all the databases again we need to be root again so mysql -uroot -p[root_password] < alldatabases.sql
That’s it at its simplest, now you have no excuse to back-up your databases!