Importing zipped files in Mysql using CMD

人走茶凉 提交于 2020-01-01 16:39:10

问题


I am trying to import zipped database files into Mysql using command prompt using the following command

7z < backup.sql.7z | mysql -u root test

The root user don't have any password associated with it.
test is my target blank database. I use 7zip for unzipping purpose. The zipped database i.e. backup.sql.7z is located in D drive.

But it's giving the following error

So, instead I used the following command

7z < backup.7z | mysql -u root test

Note: This time I am using backup.7z instead of backup.sql.7z

But then I get the following error

Clearly there's something wrong with my SQL syntax.

What will be the correct syntax to use then ?


回答1:


I needed to import from a compressed file as well, and stumbled upon your question. After a bit of messing around, I found that this worked for me:

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

x is the extraction command
-so makes 7-zip write to stdout




回答2:


Nothing wrong with your syntax, it's just a limitation with 7zip. It's better to use xz in this case, which doesn't put extraneous junk in stdout, or directly call the 7z.dll with your favorite programming language. 7z.exe is really meant for archive management, rather than unix-style piping, and Igor is very reluctant to change that.

If you try a plain 7z < somefile.7z you'll immediately see that all you get back is a usage list.



来源:https://stackoverflow.com/questions/11258811/importing-zipped-files-in-mysql-using-cmd

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!