由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
# -----------------------------------------------------

相关文章

SELECT a.*,b.dp_name,c.pa_name,fm_name=(CASE WHEN a.fm_n...
if not exists(select name from syscolumns where name=&am...
select a.*,pano=a.pa_no,b.pa_name,f.dp_name,e.fw_state_n...
要在 SQL Server 2019 中设置定时自动重启,可以使用 Window...
您收到的错误消息表明数据库 'EastRiver' 的...
首先我需要查询出需要使用SQL Server Profiler跟踪的数据库标...