Backup and Restore of MySQL

Thought this might be tricky but it’s reasonably easy; to backup, it’s just one command:

mysqldump -u <user> -p<password> <database> > ~/dumpfile.sql

replace <user> with an appropriately authorised user.
replace <password> with their password (note there’s no space after the “-p”).
replace <database> with the name of the database you want to export.

Once completed, dumpfile.sql contains all the SQL required to rebuild the objects within the database, it’s not a wierd binary format.

To restore, again, it’s a single command:

mysql -u <user> -p<password> <database> < dumpfile.sql

The same substitution rules apply as before. I guess the database may need to exist beforehand.

Advertisement

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 )

Connecting to %s

Follow

Get every new post delivered to your Inbox.