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!

Enjoy


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/lSFWmpHTX1 Patrick Stewart talks about meeting Sting on the set of DUNE (Funny to the EXTREME)

Shaun Freeman @Zendmaster

I added a video to a @YouTube playlist https://t.co/pmXSmod4ti Anonymous - This will Change Everything You Know... (2018-2019)

Shaun Freeman @Zendmaster

I added a video to a @YouTube playlist https://t.co/GkwTCvBfes Will Artificial Intelligence Take Over The World?

Shaun Freeman @Zendmaster

I liked a @YouTube video https://t.co/Y1ulafmsC6 Frank Abagnale: "Catch Me If You Can" | Talks at Google

Shaun Freeman @Zendmaster

I liked a @YouTube video https://t.co/NBdW2xFnqD ETS2: Special Transport DLC Trailer