37

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

Community
  • 1
  • 1
Subrata
  • 2,216
  • 3
  • 24
  • 38

4 Answers4

77

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.

Kanuj Bhatnagar
  • 1,320
  • 1
  • 14
  • 24
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

superjos
  • 12,189
  • 6
  • 89
  • 134
Subrata
  • 2,216
  • 3
  • 24
  • 38
  • 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 – Agung Sagita Feb 06 '20 at 05:30
16
zcat backup.sql.gz | mysql -u[username] -p[pswd] [db]
slavoo
  • 5,798
  • 64
  • 37
  • 39
davev
  • 169
  • 1
  • 2
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

ESG
  • 8,988
  • 3
  • 35
  • 52
  • 1
    It's showing an error like-> **xz: backup.sql.zip: File format not recognized** – Subrata Jun 29 '12 at 19:02
  • 1
    xz doesn't seem to support zip files. Only xc and lzma formats. – ESG Jun 29 '12 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 Jun 29 '12 at 20:48