Backing up your MySQL Databases
The following command will dump all databases to an sql file. Replace pass with your root database password and filename with the name of the file you wish to create such as backup.sql
# mysqldump -u<user> -p<pass> -B --all-databases > <filename> # mysqldump -uroot -pSuperPass -B --all-databases > all.sql
A single database can be backed up also.
# mysqldump -u<user> -p<pass> <database> > <filename> # mysqldump -uWiki -pBlue wikidb > wikidb.sql
Restore MySQL database from a backup file
There are many reasons you would want to restore a database from a backup file… But you should also test this on a test server just to make sure that your database backups are working correctly. Here’s the syntax:
mysql -h hostname -u username -pthepassword databasename < dumpfile.sql
Here’s an example:
mysql -h localhost -u root -ptgX!2121 < thedumpfile.sql