MySQL 使用 .sql.gz 文件还原数据库时 gunzip 附近的 SQL 语法错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16125603/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 17:24:40  来源:igfitidea点击:

SQL syntax error near gunzip when restoring a database using .sql.gz file

mysqldatabasewindowsphpmyadmindatabase-restore

提问by Vikalp Jain

I am trying to restore a mysql db using a .sql.gz file. I am using mySql console to run a command because file size is too large for phpMyAdmin. Command I am using is

我正在尝试使用 .sql.gz 文件恢复 mysql 数据库。我正在使用 mySql 控制台运行命令,因为文件大小对于 phpMyAdmin 来说太大了。我正在使用的命令是

gunzip C:/Vik/Gya/Source/beed_2013-04-06.sql.gz | mysql -u root -p bd

where root is the user id. There is no password for root. bd is the database to which I am trying to import. mysql is running on my local machine (Windows 8). I have a wamp setup.

其中 root 是用户 ID。root 没有密码。bd 是我要导入的数据库。mysql 在我的本地机器上运行(Windows 8)。我有一个 wamp 设置。

This is the error I am getting:

这是我得到的错误:

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'gunzip C:/Vikalp/Gyankosh/Source/beedictionary_2013-04-06.sql | mysql -u root -p'at line 1.

ERROR 1064 (42000):您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以获取'gunzip C:/Vikalp/Gyankosh/Source/beedictionary_2013-04-06.sql | mysql -u root -p'在第 1 行附近使用的正确语法。

采纳答案by álvaro González

If you type gunzipand you get a SQL syntax error that complaints about gunzip, you are already logged into the mysql console. The mysql console is not a general purpose shell!

如果你输入gunzip并得到一个 SQL 语法错误,抱怨 gunzip,你已经登录到 mysql 控制台。mysql 控制台不是通用外壳!

You are using Windows and I suspect you haven't installed gzip in your computer (it isn't a builtin utility). It's a classical Unix tool but you can find binaries for Windows. Install it and run your original command with a couple of tweaks:

您使用的是 Windows,我怀疑您没有在计算机中安装 gzip(它不是内置实用程序)。这是一个经典的 Unix 工具,但您可以找到适用于Windows 的二进制文件。安装它并通过一些调整运行您的原始命令:

  1. Make sure you're in Windows prompt (C:\>)

  2. Redirect gunzip result to stdoutrather than a file:

    gunzip --stdout C:/Vik/Gya/Source/beed_2013-04-06.sql.gz | mysql -u root -p bd
    
  1. 确保您处于 Windows 提示符 ( C:\>)

  2. 将 gunzip 结果重定向到标准输出而不是文件:

    gunzip --stdout C:/Vik/Gya/Source/beed_2013-04-06.sql.gz | mysql -u root -p bd
    

Alternatively, you can run the dump from within MySQL promt (mysql>) if you uncompress it first (you don't need specifically command-line gzip, most GUI archivers such as 7-Zipsupport this format):

或者,mysql>如果您先解压缩它,您可以从 MySQL promt ( ) 中运行转储(您不需要专门的命令行 gzip,大多数 GUI 归档程序,例如7-Zip 都支持这种格式):

mysql> \. C:/Vikalp/Gyankosh/Source/beedictionary_2013-04-06.sql

回答by kisoft

You need -c option (output to stdout)

您需要 -c 选项(输出到标准输出)

gunzip -c xxx.sql.gz |mysql -u root -p

回答by Comocho00

While Kisoft′s answer is the correct one, I just wanted to point out that you don′t need the -c, it works just fine as it is. this command will unzip the database dump and import it into the database at the same time.

虽然 Kisoft 的答案是正确的,但我只想指出您不需要 -c,它可以正常工作。此命令将解压缩数据库转储并同时将其导入数据库。

gunzip < output.sql.gz | mysql -u <username> -p<password> <database>

回答by Wayne Tun

Your answer is already here

你的答案已经在这里

phpMyAdmin: Can't import huge database file, any suggestions?

phpMyAdmin:无法导入庞大的数据库文件,有什么建议吗?

Under php.ini file, normally located in c:\xampp\php or wampp whatever you called

在 php.ini 文件下,通常位于 c:\xampp\php 或 wampp 中,无论您调用什么

post_max_size=128M
upload_max_filesize=128M

Changing value there will get you what you want.Good luck Dont forget to restart , apache and mysql .

改变那里的价值会得到你想要的东西。祝你好运 不要忘记重新启动 apache 和 mysql。

回答by Mirel

you do not need to gunzip just: zcat myfile.gz | mysql -uuser -ppassword mydatabase it is faster this way

您不需要直接压缩: zcat myfile.gz | mysql -uuser -ppassword mydatabase 这样更快

回答by kd12

Try this following steps to restore db using .gz files:

尝试按照以下步骤使用 .gz 文件恢复数据库:

1. Run command : gunzip C:/Vik/Gya/Source/beed_2013-04-06.sql.gz

This will uncompress the .gz file and will just store beed_2013-04-06.sql in the same location.

这将解压缩 .gz 文件,并将 beed_2013-04-06.sql 存储在同一位置。

2. Type the following command to import sql data file:
      mysql -u username -p bd < C:/Vik/Gya/Source/beed_2013-04-06.sql