Skip to content

Instantly share code, notes, and snippets.

@infusion
Last active May 4, 2023 06:00
Show Gist options
  • Star 19 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save infusion/492418723b6736784af1 to your computer and use it in GitHub Desktop.
Save infusion/492418723b6736784af1 to your computer and use it in GitHub Desktop.
Import a tar.gz file to MySQL
tar xOf dump.sql.tar.gz | mysql -u $user -p $database
@joshuapinter
Copy link

I don't think you need the z when extracting:

In extract or list modes, this option is ignored.

@infusion
Copy link
Author

Thanks, maybe this changed somewhere in time, I learned the options once and never looked it again

@joshuapinter
Copy link

joshuapinter commented Sep 13, 2020

👍 I hear that! Really useful so thanks for posting.

@joshuapinter
Copy link

Came back to this yet again to figure out how to do this.

I thought I would add this method to obtain the estimated progress and completion time:

  1. Install pv. On macOS, you can do brew install pv.

  2. pv dump.sql.tar.gz | tar xO | mysql -u $user -p $database

And you'll get a real-time output like this:

Screenshot 2021-02-02 at 09 10 31

@xZero707
Copy link

xZero707 commented Mar 30, 2021

Simple and effective:
zcat dump.sql.tar.gz | mysql -u $user -p $database

zcat is cat equivalent that also decompresses archive.

@sebestenyb
Copy link

On OSX zcat might not work like that, you need zcat < dump.sql.tar.gz | mysql -u $user -p $database

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment