加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

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

发布时间:2020-12-12 08:26:34 所属栏目:MsSql教程 来源:网络整理
导读:我有一系列用于创建模式的脚本,在每条指令之前都有如下所示的注释: ---------------------------------------------------------- Table TABLE_NAME-------------------------------------------------------- 当我在命令行上从mysql执行脚本时,我得到一堆如
我有一系列用于创建模式的脚本,在每条指令之前都有如下所示的注释:
--------------------------------------------------------
--  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
# -----------------------------------------------------

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读