A Quick MySQL Backup And Restore

A Quick MySQL Backup And Restore

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!


16/04/2014 11:21:00 Shaun Freeman Filed Under: MySQL MySQL

Twitter Feed
Shaun Freeman @Zendmaster

Shaun Freeman @Zendmaster

I liked a @YouTube video https://t.co/8nGfvmdsI2 From Carnivore Diet to Near-Death: Lessons Learned From Today's Most Popular Fad Diet

Shaun Freeman @Zendmaster

I liked a @YouTube video https://t.co/EFLh2y3I24 Carnivore Diet – Myths about Meat – Phil Escott – WHIS 2018

Shaun Freeman @Zendmaster

I liked a @YouTube video https://t.co/dTcBFM4q5A WHY I STOPPED BEING VEGAN | MY STORY

Shaun Freeman @Zendmaster

I liked a @YouTube video https://t.co/RVuVCieSsD Dr. Paul Mason - 'Low Carb from a Doctor's perspective'

Shaun Freeman @Zendmaster

I added a video to a @YouTube playlist https://t.co/MFRRuBG23F It's Already Too Late - Elon Musk