0

I created and compressed (with bzip2) a SQL dump from a production server on Linux.

I want to create a shell script to automatically import it in the database of my development environment (on Mac OS).

The file dump.sql.bz2 is well uncompressed manually with Mac OS Archive Utility. But when I'm using command line such as bzip2 -dck dump.sql.bz2 or bunzip2 -k dump.sql.bz2, sql file is converted in binary and can't be exploited by mysql (ERROR at line 1: Unknown command '\%'), as you can see in this screenshot:

Comparison between GUI and CLI bzip2 extraction

What is equivalent command line of Archive Utility to extract a bz2 sql file on Mac without corrupt it? May be it's not the best way do do what I want ?

Klemart3D
  • 1
  • 3

3 Answers3

0

This worked for me.

bunzip2 < db.sql.bz2 | mysql -u root -p my_local_database
Usama Munir
  • 101
  • 1
0

Well, I found why. My SQL dump was compressed two times, but name was not dump.sql.bz2.bz2, just dump.sql.bz2. Binary file was the decompression result of only first layer. Mac OS Archive Utility is more intelligent because it recognized this double compression and had restored the original SQL dump file.

Klemart3D
  • 1
  • 3
  • Automatic deep decompression is not a good idea. A Zip-bomb eat up your disk space if you use this kinda tools. – mootmoot Jun 10 '16 at 14:00
-1

This will fix your problem

bunzip2 -dk dump.sql.bz2 
# or 
bunzip2 -ck dump.sql.bz2 > myfile.sql

-c switch are mean to output to stdout, you must point the stdout result to somewhere when you use -c

mootmoot
  • 304
  • 1
  • 6