With mysqldump, you have a handy tool for creating logical backups of your MySQL databases. The result of a mysqldump operation is a SQL file, which can be utilized later to restore one or multiple databases.
Well, Gzip can work in harmony with mysqldump to reduce the output size. It offers 9 compression stages, with 6 being the standard one.
We want to generate a dump and shrink it using gzip (standard compression level). We can accomplish this with the command below:
mysqldump -u username -h localhost -p database_name | gzip > backup_db.sql.gz
Suppose we want to backup the database, but now with a compression level of 8. We can execute it with the command below:
mysqldump -u username -h localhost -p database_name | gzip -8 > backup_db.sql.gz