Posts

Showing posts from August, 2019

commandline mysql backup restore with compression sql.gz

Image
When you do mysql database backup from commandline it is good for a bigger database to use compression . It prevents backup to have bigger size and will reduce bandwidth usage also in case of remote backup. A strandard  command for backing up mysql database is as bellow   # mysqldump -u <user> -p<password> <databasename>  >  dbbackupfile.sql Example : in case db name is mydb1, user is dbuser1, password  password123. # mysqldump -u dbuser1 -ppassword123 mydb1 > mydb1bkp.sql In above now you can apply comperssion to reduce size of output backup file. # mysqldump -u dbuser1 -ppassword123 mydb1 | gzip -9 > mydb1bkp.sql.gz Now while restoring this use bellow # gunzip -p mydb1bkp.sql.gz | mysql -u dbuser1 -ppassword123 mydb1 Using above command  -p switch with gunzip pipes the output to mysql command for given database.