Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I've written a script which backups my MySQL database and produces a GZIP file with the mysql dump of my database. I wondered if it's possible to decompress the GZIP file and restore the database in one single command?

Something like this:

mysql -u user -h host -ppass database < gzip -c database.backup

But this doesn't seem to work. Any suggestions?

I use the following command:

mysqldump -u user -h host -ppass database | gzip -9 > database.backup

The error I get is: -bash: gzip: No such file or directory; which, in my opinion, indicates that it does not recognise gzip as a command or something like that

share|improve this question
    
No, it indicates that the database.backup file doesn't exist. Are you sure it's there? –  slhck Feb 28 '13 at 15:20

2 Answers 2

up vote 1 down vote accepted

You're using two commands so you should use a pipe and not redirection. I use this:

gunzip < file.gz | mysql <parameters>
share|improve this answer
    
Thank you! worked like a charm! :) –  Flock Dawson Feb 28 '13 at 15:29

Normally this should work. Is gzip installed and available in the PATH-Variable ? (You can test it with command "which gzip"

mysqldump -u user -h host -ppass database | gzip -9 > database.backup

but i would use as backup-file the suffix .gz

You also can try

mysqldump -u user -h host -ppass *--database* "db_name" | gzip -9 > "db_backup".backup.gz

I wrote a script recently to make a compressed backup of my databases.

http://infofreund.de/easy-mysql-backup/

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.