How to Backup a MySQL Database with mysqldump
One of the most common ways of backing up with MySQL is to use a command called “mysqldump”.
Backing Up
- There is an article on how to export databases using mysqldump here. The basic syntax of the command is:
1
mysqldump -u username -p database_to_backup > backup_name.sql
Restoring
- To restore a database dump created with mysqldump, you simply have to redirect the file into MySQL again.
We need to create a blank database to house the imported data. First, log into MySQL by typing:1
mysql -u username -p
- Create a new database which will hold all of the data from the data dump and then exit out of the MySQL prompt:exit
1
CREATE DATABASE database_name;
- Next, we can redirect the dump file into our newly created database by issuing the following command:Your information should now be restored to the database you’ve created.
1
mysql -u username -p database_name < backup_name.sql