# mysqldump & gzip

mysqldump can be easily combined with Gzip in order to reduce the size of the database dump. First, you have to execute the mysqldump command as usual. Next, instead of storing the output in a file, you must pipe it to gzip. Finally, the gzip output will be stored in a file with the .sql.gz extension. See an example below.

# mysqldump a single database to gzip

# Gzip compression level 6 is used by default
mysqldump my_app | gzip > my_backup.sql.gz

# Compress the dumo using a different level
mysqldump my_app | gzip -8 > my_backup.sql.gz

# Compression levels

Gzip has 9 compression levels, 6 being the default one. A lower level means a faster execution of the compression with a bigger archive size. A bigger level does the opposite: longer execution time with smaller archive size.

It's up to you to decide what is more important for your use case but, in general, the default compression level (6) is the best option because it has the best compression/speed ration.