Mysql不支持单行注释.原因是什么?

Che*_*lla 7 mysql command-line comments

这是我使用单行注释(使用-)时得到的内容.错误1064(42000):您的SQL语法有错误; 实际上我在一个程序中使用这些注释来显示一行究竟是什么.然后我直接在mysql命令行检查,但是我收到了这个错误.

mysql> select 1;--test select
+---+
| 1 |
+---+
| 1 |
+---+
1 row in set (0.00 sec)

    -> ;
check the manual that corresponds to your MySQL server version for the right syntax to use near '--test select' at line 1
Run Code Online (Sandbox Code Playgroud)

我用Google搜索并浏览了mysql文档,其中显示了我,它是supoppots(-).可能是什么错误?

Ale*_*TMH 14

从mysql文档:

从" - "序列到行尾.在MySQL中," - "(双破折号)注释样式要求第二个破折号后跟至少一个空格或控制字符(例如空格,制表符,换行符等).

所以你需要一些空格字符--,例如:

mysql> select 1;-- test select
Run Code Online (Sandbox Code Playgroud)


Rom*_*aza 5

您的语法有误-请阅读注释语法

只需在之后添加一个空格--

mysql> select 1; -- test select
+---+
| 1 |
+---+
| 1 |
+---+
1 row in set (0.00 sec)
Run Code Online (Sandbox Code Playgroud)