Skip to content

Backing up Mysql Databases

June 8, 2012

Now to backup the databases I will use mysqldump, this is one of the preferred ways to backup as recommended by mysql (http://dev.mysql.com/doc/refman/5.5/en/using-mysqldump.html)

To create a backup of a specific database you do: –

prompt> mysqldump -u bob -p –databases name_of_database > backup_of_database.sql

The above will create a backup of the database on the form of backup_of_database.sql

Now to restore the database into mysql if it ever got deleted you would do: –

prompt> mysqldump -u bob -p –databases name_of_database < backup_of_database.sql

Make sure that the database name has been created in mysql before you start restoring a backup otherwise you will receive an error message saying that it can’t find the database. Note that the only change to the commmands are the redirection, i.e. > and <

You can always create the database by using the following command: –

mysql> CREATE DATABASE name_of_database_you_want_to_create;

Quite simple stuff but it works well. You can always archive and compress using tar to make the backup data size smaller and to archive multiple backups into one archive. Furtermore if you look at the man page you can quite easily backup all the databases with a simple argument too.

Advertisements

From → Linux

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: