Gunzip is an awesome terminal feature that is the opposite of "gzip", which allows you to compress a file via .gz so that it is much smaller than even a zip file. For the most part, gzip is used to zip up entire directories, but in many cases, the .sql file, which allows it to be compressed to a much smaller filesize. A normal sql file might end up being about 20 MB, but once gzipped becomes 2 MB.
So the easiest way to gzip a file via command:
To uncompress this gzip file, the terminal command is fairly easy, but sometimes it may not always work.
Here is how most websites say to do it:
gunzip < myfile.sql.gz
Sometimes this works, sometimes it doesn't. I had programatically had been entering this code and I kept receiving errors that my database wasn't restored.
So after trying several different methods, this one worked for me:
gunzip -r -f -k myfile.sql.gz
Adding the -r attribute recursively goes through every directory to gunzip it (in case for whatever reason gzip put it in a separate directory).
Adding the -f attribute forces the files to be overwritten regardless if they exist or not.
Adding the - k attribute keeps the original gzip file otherwise it is destroyed.
This seems to have outputted the original myfile.sql from myfile.sql.gz.
Hope this works for you!