Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL is not supporting single line comments here. What would be the reason?

Here is what I am getting when I use single line comment (using --):

ERROR 1064 (42000): You have an error in your SQL syntax

Actually I am using these comments in a procedure to show what exactly a line does. Then I checked directly at the MySQL command line, but I got this error:

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

Do I need to configure a file to support this? It is working fine if I use multi-line comments (using /* Something */).

I googled and went through MySQL documentation. In that it has shown me it supports ( -- ). What could be the error?

like image 283
Chella Avatar asked Jan 21 '13 09:01

Chella


People also ask

Which is not a valid comment style in MySQL?

Nested comments are not supported, and are deprecated; expect them to be removed in a future MySQL release.

How do you comment multiple lines in MySQL?

Multi-line comments start with /* and end with */ . Any text between /* and */ will be ignored.

What is /* in MySQL?

This is a type of comment. The /* is the beginning of a comment and */ is the end of comment. MySQL will ignore the above comment.

How do I comment out in MySQL SQL?

Syntax Using /* and */ symbols In MySQL, a comment that starts with /* symbol and ends with */ and can be anywhere in your SQL statement. This method of commenting can span several lines within your SQL.


1 Answers

From MySQL documentation:

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).

You need some space character after --, for example:

mysql> select 1;-- test select
like image 87
AlecTMH Avatar answered Sep 29 '22 07:09

AlecTMH