微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

由SQL注释触发的Mysql错误1064(“您的SQL语法中有错误”)

我有一系列用于创建模式的脚本,在每条指令之前都有如下所示的注释:
--------------------------------------------------------
--  Table TABLE_NAME
--------------------------------------------------------

当我在命令行上从MysqL执行脚本时,我得到一堆如下错误

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 '------------------------------------------------------
------------------------' at line 1

(实际上,每个评论都会出现一个错误,尽管消息总是引用第1行).

为了快速解决我的问题,我只是删除了注释,脚本运行没有问题,但我很惊讶地看到这样的行为,并且无法在stackoverflow上找到相关的问题.有人有解释吗?有没有人观察到这种奇怪的行为?

我正在运行MysqL 5.6.30,这是ubuntu上5.6的认值.

解决方法

MySQL Manual

From a “– ” sequence to the end of the line. In MysqL,the “– ”
(double-dash) comment style requires the second dash to be followed by
at least one whitespace or control character (such as a space,tab,
newline,and so on). This Syntax differs slightly from standard sql
comment Syntax,as discussed in Section 1.8.2.4,“’–‘ as the Start of
a Comment”.

(重点我的)

tl; DR你的 – 表示评论必须后跟至少一个空格或控制字符.

修正了你的代码

-- -----------------------------------------------------
--  Table TABLE_NAME
-- -----------------------------------------------------

MysqL中您也可以使用以下语法:

/* 
*    Table TABLE_NAME
*/

甚至这个:

# -----------------------------------------------------
#   Table TABLE_NAME
# -----------------------------------------------------

原文地址:https://www.jb51.cc/mssql/76085.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐