Comments are skipped when a dump is loaded, except for a special kind in MySQL dumps that the server runs. The start of a dump is usually comments from the tool, saying what made it and when.
Comment styles
| Style | Runs to | Dialects |
|---|---|---|
-- text | The end of the line | All. MySQL needs a space or control character after the second dash, so 1--1 is a subtraction. |
# text | The end of the line | MySQL and MariaDB |
/* text */ | The closing */ | All. Block comments nest in PostgreSQL and SQL Server, and do not nest in MySQL. |
MySQL’s executable comments
Text inside /*! and */ is treated by MySQL as if it were not
in a comment, and by other servers as a comment. This lets a dump use features that only
some servers have.
/*!40101 SET NAMES utf8mb4 */;
/*!40000 ALTER TABLE `fruit` DISABLE KEYS */;
CREATE TABLE t (a int, KEY (a)) /*!50110 KEY_BLOCK_SIZE=1024 */;
A number after the ! is a minimum version. It has five digits in the form
Mmmrr, so 40101 means 4.1.1 or later, and
50110 means 5.1.10 or later. The code runs only on a server of that version
or later, and without a number it runs on any MySQL server. MariaDB adds its own form,
/*M!100100 … */, which only MariaDB runs.
To read a MySQL dump correctly, the contents of these comments have to be read as code, including the semicolons and quotes in them.
Comments of the form /*+ … */ are optimizer hints. They do not appear in
dumps.
Comments that tools write
| Tool | Writes |
|---|---|
| mysqldump | -- MySQL dump … and -- Table structure for table …; -- Dump completed on … at the end. --skip-comments leaves them out. |
| pg_dump | -- PostgreSQL database dump, and a line before each object giving its name and type |
| Management Studio | /****** Object: Table [dbo].[t] Script Date: … ******/ |