Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

For some reason gzip doesn't work. It gives me an empty file

/usr/bin/mysqldump --opt -u root -ppassword database > database.sql | gzip > database.sql.gz

database.sql is correctly created and it has the correct size.

However database.sql.gz is only 20kb and it contains an empty file.


share|improve this question
up vote 5 down vote accepted

Try this

/usr/bin/mysqldump --opt -u root -ppassword database | gzip > database.sql.gz
share|improve this answer

Your syntax is wrong here. Because you're sending the output from the mysqldump command to database.sql, there's no output left to be piped through to gzip. Just remove that bit, so you're only creating the gzipped file: /usr/bin/mysqldump --opt -u root -ppassword database | gzip > database.sql.gz

If you really want to create compressed and uncompressed versions, you'll either need to run two separate commands: /usr/bin/mysqldump --opt -u root -ppassword database > database.sql ; cat database.sql | gzip > database.sql.gz

or use tee to split the output: /usr/bin/mysqldump --opt -u root -ppassword database | tee database.sql | gzip > database.sql.gz

share|improve this answer

pipeline means that you are NOT writing to file, so just remove " > database.sql" in your one-liner.

Try something like this instead:

/usr/bin/mysqldump --opt -u root -ppassword database | gzip > database.sql.gz

share|improve this answer

Because there is no more ouput after the creation of the sql file database.sql. It does not continue so the pipe does not receive any data. you could do this: mysqldump -u root -p auth > data.sql && gzip data.sql

share|improve this answer

The problem is that you are trying to redirect the output both to a file and to a pipe.

If you want to compress the output of the command to a file you must use:

/usr/bin/mysqldump --opt -u root -ppassword database | gzip > database.sql.gz
share|improve this answer

Your Answer


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.