How to import compressed MySQL file on the command line
Jan 5, 2017
1 minute read

zcat restores compressed files to their original forms, while pv monitor the progress of data through a pipe (in other words, allows users to view a progress of a data through a pipeline).

Combining these two commands we can import a compressed MySQL database while vieweing the progress.

The final command is:

zcat database.sql.gz | pv -cN zcat | mysql -u user -p dbname

In case it fails on your operational system, here’s a variation:

pv bigdump.sql.gz | gunzip | mysql -u user -p dbname

In case MySQL data is a full dump, the dbname can be ommited.