intro
This definitive guide will walk you through everything you need to know when working with commenting in MySQL and related database management systems.
Many software engineers and DBAs working on specific projects often come across the necessity to comment on their code. Here’s why MySQL commenting is such a popular topic.
No matter if we’re talking about commenting something out of the code or adding specific comments to clarify how a specific piece of code may be executed during different phases, comments are a necessary part of every programming language.
Let’s dive in!
Comments in SQL
Comments have always been a part of the SQL world. When it comes to relational databases, there are three ways of commenting stuff out:
On a high level, comments are used to explain SQL statement functionality.
How Does Commenting in MySQL Look Like?
Commenting in MySQL usually looks like so:

Nothing very complex, yeah? We think so, too. That’s what you have to keep in mind:
Note: Comments using --
, the #
character, and /*
are supported in all relational database management systems but are not supported in non-relational and Microsoft Access-based databases.
Comments in MySQL: Syntax and First Examples
When it comes to commenting in MySQL, things are simple. As already mentioned before, we have three ways of commenting stuff out:
Comments are not all the same for all database management systems, the same can be said about MySQL.
Many users of MySQL will find this type of commenting familiar:
1
/*!80000
2
Comment here!
3
*/
Here, the number 80000
in the MySQL comment targets MySQL 8.0.00 or above and the same can be said about other numbers too. In regards to versioning, MySQL uses this format:
1
MMmmrr
Where:
Keep in mind that such “version-based” commenting is only applicable to multiple-line comments.
MySQL supports comments that are different from C-style comments. These include:
The first comment is only applicable to MySQL Server, but not to Percona Server or MariaDB. Find out more in our guide on MariaDB vs MySQL.
In the third comment, +
specifies a hint for the query optimizer. Invoking MySQL in the binary mode (using the --binary-mode
option) prevents the query optimizer from storing such comments in the object definitions.
Comments using the version numbers are not stored on the server. MySQL does not support “short-form” comments supported by some CLI appliances either (here we’re talking about commenting using C
to precede and end comment blocks.)
Comments in Other Database Management Systems
As already mentioned before, different database management systems come with different commenting conventions, too, and not all comments are the same across the database world. For example, NoSQL databases such as MongoDB precede and end comments with //
or “embed” them in a JSON document like so:
1
{
2
"_id": ObjectId(123),
3
"username": "Username",
4
"about": "Some text...",
5
"comments": [
6
{
7
"name": "Demo",
8
"body": "Comment!"
9
},
10
{
11
"name": "Some comment!",
12
"body": "Comment here too!"
13
},
14
{
15
"name": "Demo for DbVisualizer",
16
"body": "This is a comment as well."
17
}
18
]
19
}
Using another database management system? Make sure to refer to its documentation for comment examples and use cases.
Summary
Commenting in MySQL is not hard, but it’s not like eating a piece of cake either. One can approach comments in MySQL in one of three ways:
It may seem simple and straightforward, but as with everything, comments in MySQL come with a bunch of things necessary for you to know, such as the versioning numbers at the beginning of the comment block or certain C-style comments.
There are many other problems you should be wary about, too — these include problems with your database performance, availability, or security implications and for that, you should consider using a state-of-the-art database client, such as DbVisualizer.
DbVisualizer not only has a powerful SQL editor, but it also allows you to optimize your database instances and explore and visualize the data within them.
We hope that this blog helped you better understand commenting in MySQL, and until next time!
FAQ
How does commenting in MySQL work?
One can approach commenting in MySQL in one of three ways: using #
or --
for one-line comments, or using /*
and */
for multiple-line comments.
What do the numbers after a multiple-line comment mean?
The numbers after the /*!
code block denote the version of MySQL. Such numbers frequently appear in MySQL dump files from phpMyAdmin.
Why aren’t comments the same in all DBMS?
Comments in MySQL aren’t the same as comments in MongoDB or other database management systems. That is because of the way we interact with different database management systems differs from MySQL, and as such, comments are implemented differently too.
Where can I learn more about databases?
Feel free to binge our blog TheTable, or watch educational database-based YouTube videos through our friends Database Dive on YouTube. See you there!