Dump and restore zipped DB
Dump:
mysqldump -u<user> -p <dbname> -h <host> | bzip2 > dump.sql.bZ2
If your database on localhost
, just skip -h <host>
If you want to include CREATE DATABASE
statement use --databases <dbname>
instead of <dbname>
Restore:
bzcat dump.sql.bZ2 | mysql -u<user> -p -D<dbname> -o
You can also set password in command line instead of entering it by prompt:
mysqldump -u<user> -p<password> ...
But remember that it will remain in your history (e.g. ~/.bash_history
)