Backup and Restore Databases With MySQL Dump

This handy command line snippets allow us to import and export databases or tables with mysql built in function. Mysqldump command can be configured to export databases, or just a table.

SQL

The following command uses mysqldump to export databases and tables.

//Export Database
mysqldump -uUsername -p Database > db_backup.sql

//Export Multiple databases
mysqldump -uUsername -p --databases db_name1 [db_name2 ...] > db_backup.sql

//Export All databases
mysqldump -uUsername -p --all-databases > db_backup.sql

//Export a table 
mysqldump -uUsername -p Database Tablename > table_backup.sql

//Export multiple tables
mysqldump -uUsername -p Database Table1 [Table2 ...]  > tables_backup.sql

SQL

Restore database or tables from mysqldump file

mysql -u username --p database_name < dump.sql

Share the love

Leave a Comment

Please keep in mind that comments are moderated and rel="nofollow" is in use. You can use [code][/code] if you want to write codes. Don't spam us :) Thanks!

Advertisement