Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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.

thanks

share|improve this question

5 Answers 5

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

 
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.