MySQL 错误代码 1064,SQL 状态 42000:您的 SQL 语法有错误;

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15113707/
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 16:41:53  来源:igfitidea点击:

Error code 1064, SQL state 42000: You have an error in your SQL syntax;

mysqlnetbeansjdbc

提问by Hazem Taha

I'm using latest version of MySQL ==> mysql-5.6.10-winx64.zip

我正在使用最新版本的 MySQL ==> mysql-5.6.10-winx64.zip

Created the database and every thing is ok 'I think' when I try to execute this simple command;

创建了数据库,当我尝试执行这个简单的命令时,“我认为”一切正常;

"select * from family"

I got this error :

我收到此错误:

Error code 1064, SQL state 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 'OPTION SQL_SELECT_LIMIT=DEFAULT' at line 1

错误代码 1064,SQL 状态 42000:您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以获取在第 1 行的“OPTION SQL_SELECT_LIMIT=DEFAULT”附近使用的正确语法

I've spent much time searching for a solution but no solution was found :(

我花了很多时间寻找解决方案,但没有找到解决方案:(

回答by hrunting

That looks like an error coming from a JDBC driver. When the JDBC driver initializes the connection, it sends several commands to the MySQL server, one of which is:

这看起来像是来自 JDBC 驱动程序的错误。当 JDBC 驱动程序初始化连接时,它会向 MySQL 服务器发送几个命令,其中之一是:

SET OPTION SQL_SELECT_LIMIT=DEFAULT

The problem is that the SET OPTIONsyntax has been deprecated for some time and is now no longer valid in MySQL 5.6. Here's a relevant bug conversation from MySQL's bug database:

问题是该SET OPTION语法已经弃用了一段时间,现在在 MySQL 5.6 中不再有效。以下是来自 MySQL 错误数据库的相关错误对话:

Bug #66659: mysql 5.6.6m9 fails on OPTION SQL_SELECT_LIMIT=DEFAULT

错误 #66659:mysql 5.6.6m9 在 OPTION SQL_SELECT_LIMIT=DEFAULT 上失败

Try upgrading your JDBC MySQL driver. The bug conversation lists some other options in case upgrading the driver is not an option.

尝试升级您的 JDBC MySQL 驱动程序。错误对话列出了一些其他选项,以防升级驱动程序不是一种选择。

回答by Fresh

I followed the instructions above and this worked for me!

我按照上面的说明进行操作,这对我有用!

  1. Download latest jar file from here: http://dev.mysql.com/downloads/mirror.php?id=412737Unzip it Copy jar file "mysql-connector-java-5.1.25-bin.jar" to this folder: C:\Program Files\NetBeans 7.3\ide\modules\ext

  2. In Netbeans IDE: Disconnect from database. Click Services. Expand Drivers. Right-click on MySQL and press Customize. Add latest driver Remove previous driver.

  3. Re-connect to dabatase within IDE.

  1. 从这里下载最新的 jar 文件:http: //dev.mysql.com/downloads/mirror.php?id=412737 解压 将 jar 文件“mysql-connector-java-5.1.25-bin.jar”复制到这个文件夹: C:\Program Files\NetBeans 7.3\ide\modules\ext

  2. 在 Netbeans IDE 中:断开与数据库的连接。单击服务。展开驱动程序。右键单击 MySQL,然后按自定义。添加最新的驱动程序 删除以前的驱动程序。

  3. 在 IDE 中重新连接到 dabatase。

回答by farmbytes

I had the same problem few weeks back. Followed the following steps and it very much resolved the issue.

几周前我遇到了同样的问题。按照以下步骤操作,它很好地解决了问题。

  1. Copied the latest version (mysql-connector-java-5.1.23-bin) of the jar file to ..\NetBeans 7.3\ide\modules\ext. My earlier version of the driver was mysql-connector-java-5.1.18-bin.

  2. Change the driver version within NetBeans IDE. In the IDE's Services window, expand Drivers -> right-click on MySQL (Connector/J driver) and select Customize. Remove the earlier driver and point it to the latest one (C:\Program Files (x86)\NetBeans 7.3\ide\modules\ext\mysql-connector-java-5.1.23-bin.jar). Click ok and restart IDE.

  1. 将jar文件的最新版本(mysql-connector-java-5.1.23-bin)复制到..\NetBeans 7.3\ide\modules\ext。我早期版本的驱动程序是 mysql-connector-java-5.1.18-bin。

  2. 在 NetBeans IDE 中更改驱动程序版本。在 IDE 的服务窗口中,展开驱动程序 -> 右键单击​​ MySQL(连接器/J 驱动程序)并选择自定义。删除较早的驱动程序并将其指向最新的驱动程序(C:\Program Files (x86)\NetBeans 7.3\ide\modules\ext\mysql-connector-java-5.1.23-bin.jar)。单击确定并重新启动 IDE。

This should resolve the problem.

这应该可以解决问题。

回答by Brice

If the driver suggestion does not work, check your sql for unprintable characters. I just spent an hour troubleshooting this issue only to discover a hidden u+200b character at the end of my sql statement.

如果驱动程序建议不起作用,请检查您的 sql 是否存在不可打印的字符。我只花了一个小时来解决这个问题,结果在我的 sql 语句末尾发现了一个隐藏的 u+200b 字符。

回答by D8Sasi

I got the same Error when i was dumping mysql table structure file in to DB. Mistake was putting the Syntax for dropping all table before but not checking their existence in the Database. Issue was at " DROP TABLE usermgmt". I removed that code of lines of dropping tables and it proceeded with out any error this time.

当我将 mysql 表结构文件转储到数据库时,我遇到了同样的错误。错误是在之前放置了删除所有表的语法,但没有检查它们在数据库中的存在。问题出在“ DROP TABLE usermgmt”上。我删除了删除表行的代码,这次它没有出现任何错误。

回答by rachid el kedmiri

I prefixed the name of the table with the database name such as

我用数据库名称作为表名的前缀,例如

select * from database_name.table_name;

and it worked perfectly, so most likely there's a name conflict.

它工作得很好,所以很可能存在名称冲突。