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
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.
This is the command I use to backup all databases in MySQL:
mysqldump -u USERNAME -p --all-databases --events --ignore-table=mysql.event --extended-insert --add-drop-database --disable-keys --flush-privileges --quick --routines --triggers | gzip > "all_databases.gz"
To restore from a *.gz mysqldump file:
gunzip < all_databases.gz | mysql -u USERNAME -p
To display a progress bar while importing a sql.gz file, download pv and use the following:
pv mydump.sql.gz | gunzip | mysql -u root -p
If PV command is not installed on your system then try below command relatively
In CentOS/RHEL
yum install pv
In Debian/Ubuntu
apt-get install pv
In MAC
brew install pv
Output Something like that -->
pv mydump.sql.gz | gunzip | mysql -u root -p dbname
Enter password:
255MiB 0:05:49 [ 748kiB/s] [===========> ] 30%
/ applications / MAMP / library / bin / mysql -u根-p <all_dbs2.sql
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.