Importing zipped files in Mysql using command line
Asked Answered
D

4

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

Daukas answered 29/6, 2012 at 18:43 Comment(0)
D
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

Daukas answered 28/8, 2012 at 6:55 Comment(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 hintSnout
B
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.

Bruyn answered 12/11, 2015 at 6:54 Comment(3)
you must have installed unzip, you can install unzip, if not installed. sudo apt-get install unzipMinoan
@Minoan - yes, I did have unzip installed... the OP's question did say that their file was zipped.Bruyn
yeah, while using unzip command in the new ubuntu machine, I had got an error, saying unzip is not installed.Minoan
D
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

Daukas answered 28/8, 2012 at 6:55 Comment(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 hintSnout
E
17
zcat backup.sql.gz | mysql -u[username] -p[pswd] [db]
Emblazonry answered 29/4, 2014 at 14:3 Comment(0)
C
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

Cletacleti answered 29/6, 2012 at 18:46 Comment(3)
It's showing an error like-> xz: backup.sql.zip: File format not recognizedDaukas
xz doesn't seem to support zip files. Only xc and lzma formats.Cletacleti
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.7zCletacleti

© 2022 - 2024 — McMap. All rights reserved.