Backup and Restore of MySQL
19 Nov 2010 Leave a Comment
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.