Dump and restore zipped DB

Today, 27th January 2023, Ukraine is still bravely fighting for democratic values, human rights and peace in whole world. Russians ruthlessly kill all civilians in Ukraine including childs and destroy their cities. We are uniting against Putinโ€™s invasion and violence, in support of the people in Ukraine. You can help by donating to Ukrainian's army.
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>

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)

Ivan Borshchov profile picture
Nov 21, 2016
by Ivan Borshchov
Did it help you?
Yes !

Best related