MySQL - Dump and Reload


mysqldump --password --user=root world > world.sql
create database world;
mysql -u root -p world < world.sql
mysqldump -h myhost -u root -pmypass dbname > dbname_backup.sql

To restore:

mysqladmin -h myhost -u root -pmypass create dbname;
mysql -h myhost -u root -pmypass dbname < dbname.sql

How can we dump schema only?

mysqldump -u someuser -p -d --routines mydatabase > mydatabase.sql
mysqldump -u someuser -p --no-data --routines mydatabase > mydatabase.sql

How can we dump all databases at the same time?

mysqldump --all-databases > all_databases.sql

To re-import all databases:

mysql -u root -p < alldb.sql
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License