41

Importing zipped files in Mysql using CMD

What is the right syntax to import sql zipped files into mysql using cmd ?

I am doing the following

xz < backup.sql.gz | mysql -u root test

But always getting the following error enter image description here

4 Answers 4

82

Try:

unzip -p dbdump.sql.zip | mysql -u root -p yourdbname

The dbdump.sql.zip should contain a single SQL file. The -p flag pipes the output into the mysql binary.

3
  • you must have installed unzip, you can install unzip, if not installed. sudo apt-get install unzip Commented Dec 11, 2019 at 14:04
  • 1
    @Allahbakash.G - yes, I did have unzip installed... the OP's question did say that their file was zipped. Commented Dec 16, 2019 at 10:11
  • yeah, while using unzip command in the new ubuntu machine, I had got an error, saying unzip is not installed. Commented Dec 17, 2019 at 10:51
20

I got the answer from my other question. This is the command to import zipped file when you are using 7zip

7z x -so backup.7z | mysql -u root test

x is the extraction command

-so option makes 7-zip write to stdout

1
  • thanks, but it worked for me if -u and username, -p and password, dont have space, hence, 7z x -so backup.7z | mysql -umysqlusername -pmysqlpassword dbname, thx for the hint Commented Feb 6, 2020 at 5:30
17
zcat backup.sql.gz | mysql -u[username] -p[pswd] [db]
0

You want might to try xz −−decompress −−stdout to decompress.

Full command would be xz −−decompress −−stdout backup.sql.gz | mysql -u root test

3
  • 1
    It's showing an error like-> xz: backup.sql.zip: File format not recognized
    – Subrata
    Commented Jun 29, 2012 at 19:02
  • 1
    xz doesn't seem to support zip files. Only xc and lzma formats.
    – ESG
    Commented Jun 29, 2012 at 19:56
  • 1
    Yes, I use it for 7z archives. Should work fine with zip files too. My command line looks like 7z.exe e -y -so current.7z
    – ESG
    Commented Jun 29, 2012 at 20:48

Not the answer you're looking for? Browse other questions tagged or ask your own question.