Back SQL

Backup and Restore Databases With MySQL Dump

WRITTEN BY ON 07 Mar 2011
12,803 VIEWS • SHARES
0 comments

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
Join the discussion

Comments will be moderated and rel="nofollow" will be added to all links. You can wrap your coding with [code][/code] to make use of built-in syntax highlighter.