formats

How to MySQL Dump and Recovery

Published on July 26, 2011, by + in sysadmin.




MySQL has the ability to dump or backup an entire database to a single recoverable file. I’ll show you how to dump and also recover!


Dump a MySQL database

To dump a mysql database, the command is:

$ mysqldump -u mysqlusername -p databasename > mybackup.sql
Enter password: (enter your mysqlusername's mysql password)


For example if there is a database as follows:

Database name: mydatabase
Database user: user1
Database pass: password for this database user

…issue this command:

$ mysqldump -u user1 -p mydatabase > 072611backup.sql
Enter password: (enter user1's mysql password)



You can also dump ALL databases into one blob for backup purposes. This requires the root mysql user.

$ mysqldump -u root -p --all-databases > db.sql


Restore a MySQL database

To recover or restore a mysql dump, use the command mysql as follows:

$ mysql -u mysqlusername -p databasename < backup.sql
Enter password: (enter your mysqlusername password)



Done!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Notify me of followup comments via e-mail. You can also subscribe without commenting.

Home sysadmin How to MySQL Dump and Recovery