Import & Export .bz2 MySQL Files

Import & export .bz2 MySQL database files with these simple commands — useful in automated shell scripts when you’re exporting from a remote DB then importing into another like your local.

A comparison between a normal dump and a bzip2 results in a 78.35% decrease in file size.

Import .bz2 MySQL File

bunzip2 < db_filename.sql.bz2 | mysql -u root -p target_db_name

Export .bz2 MySQL File

mysqldump -u username -p databasename | bzip2 > db_filename.sql.bz2

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

All comments are held for moderation and only published when on topic and not rude. You'll even get little stars if you do an extra good job.

You may write comments in Markdown. This is the best way to post any code, inline like `<div>this</div>` or multiline blocks within triple backtick fences (```) with double new lines before and after.

Want to tell me something privately, like pointing out a typo or stuff like that? Contact Me.

icon-search icon-link