MySQL Export Database to GZIP File in Linux

Last updated on Dec 30, 2019 in MySQL, Linux

You can export MySQL database from command line of Linux by using mysqldump. You only have to know MySQL user’s username and password, and the name of the database. By default, the output is in SQL format, so it is good idea to compress it on-the-fly.

Run mysqldump Piped With gzip

$ mysqldump -u username -p database_name | gzip > dump.sql.gz

Here, the -p stands for password which is prompted before continuing. You can write the password directly after the -p, but it is insecure method, since the command is stored in the command history and therefore remains visible.

The | gzip pipes the output of mysqldump to gzip which compresses it during the execution.

Finally, the > dump.sql.gz forwards the compressed output to the file named dump.sql.gz.