Sep 18, 2012

Mysql Restore

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.


//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



Restore database or tables from mysqldump file
mysql -u username --p database_name < dump.sql




No comments:

Post a Comment