restore all mysql database from a --all-database sql.gz file

ahhmarr picture ahhmarr · Apr 20, 2014 · Viewed 71.9k times · Source

I've backed all my mysql databases with he following command

mysqldump -u root -ppasswod --all-databases | gzip > all.sql.gz

just wanted to know will I be able to restore all of the database with following command

gunzip < alldb.sql.gz | mysql -u root -ppassword -h localhost

can you also tell me how to back up all of mysql users too?

I cant test it because I'm not sure and I don't want to break any db on my current system

Answer

mockinterface picture mockinterface · Apr 20, 2014

Yes. Generally, to restore compressed backup files you can do the following:

gunzip < alldb.sql.gz | mysql -u [uname] -p[pass] [dbname]

Please consult How to Back Up and Restore a MySQL Database

Note that the --all-databases option is applicable to backup only. The backup file itself will contain all the relevant CREATE DATABASE quux; commands for the restore.