Home > Tutorial > MySQL backup and restore

MySQL backup and restore

Backing up your database is important, here's some useful information to help you backup your data within the MySQL environment.

mysqldump -uUsername -p dbname > dbname.sql

That will backup your database as dbname.sql and put that file in your current directory. Mysqldump has many useful options you can use. for example, if we used -c , the dump would "Use complete Insert Statements" vs. "Incomplete" ones. See below resources for more information on options.It's worth mentioning that the mysqldump command is not required to dump a database, using mysql works just fine too, just doesn't have all the dump options. Replacing mysqldump with mysql in the above example will work but options such as -c will not work.

To also compress your dump, to take less space, you could also include gzip in your command line, such as :

mysqldump -uUsername -p dbname | gzip > dbname.gz

To import the database into a blank mysql database, do the following :

mysql -uUsername -p dbname < dbname.sql

Or if you're importing a gzipped archive then you'll do the following :

gunzip < dbname.gz | mysql -uUsername -p dbname

Categories: Tutorial Tags:
  1. No comments yet.
  1. No trackbacks yet.

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 )

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

%d bloggers like this: