Single-line comment. '#' character begins a comment that extends to the end of the line

Multi-line comments. /* … */

A — (double dash) sequence followed by a space (or control character) begins a comment that extends to the end of line. This syntax requires a space and thus differs from standard SQL, which allow comments to be introduced by — without the space. MySQL disallows a double dash without a space as comment because it is ambiguous. (For example, does 1—3 mean "one minus negative three" or "one followed by a comment"?)

The C-style (/* … */) comments can contain embedded SQL text that is treated especially by MySQL, but ignored by other database engines. This is an aid to writing more portable SQL, because it enables you to write comments that are treated as part of the surrounding statement if executed by MySQL and ignored if executed by other database servers. There are two ways to write embedded SQL in a C-style comment:

If the comment begins with /*! rather than /*, MySQL executes the body of the comment as part of the surrounding query. The following statement creates a table named t, but for MySQL creates it specifically as a MEMORY table:

CREATE TABLE t (i INT) /*! ENGINE = MEMORY */;

If the comment begins with /*! followed by a version number, the embedded SQL is version specific. The server executes the body of the comment as part of the surrounding query if its version is at least as recent as that specified in the query. Otherwise, it ignores the comment. For example, the FULL keyword for SHOW TABLES was added in MySQL 5.0.2. To write a comment that is understood only by servers from MySQL 5.0.2 and up and ignored by older servers: