In MySQL, there are 3 ways to comment out a single line or a block of SQL commands.

1. Comment out a single line using #

You can put a # character where you want to add a comment, it will comment out the codes from the next character until the end of the line.

Example:

#INSERT INTO `employees`.`orders` () VALUES ();

2. Comment out a single line using --

You can put a sequence of double dash (-- ) right at the start of the comment, it will comment out the next character until the end of the line.

Note that you need one whitespace or control character (such as space, tab, newline, and so on) right after the double dash to make it work.

Example:

-- INSERT INTO `employees`.`orders` () VALUES ();

3. Comment out multiple lines using /* */

You can put a sequence of /* at the start and */ at the end of the code block. Unlike the two methods above that only continue to the end of the line, this method will continue to comment out the codes until it meets the end sequence (*/).

Example:

/*INSERT INTO `employees`.`orders` () VALUES ();
INSERT INTO `employees`.`orders` () VALUES ();
DELETE FROM `employees`.`orders` WHERE `id` = '13';*/

4. Bonus: Quick comment in TablePlus

When using TablePlus query editor, you can quickly turn a single line or multiple lines of queries into comments by selecting the part you want to comment out and press shortcut keys Cmd + /

If you want to uncomment, just select the part and press Cmd + / again.

Comment out


Need a good GUI tool for databases? TablePlus provides a native client that allows you to access and manage Oracle, MySQL, SQL Server, PostgreSQL, and many other databases simultaneously using an intuitive and powerful graphical interface.

Download TablePlus for Mac.

Not on Mac? Download TablePlus for Windows.

On Linux? Download TablePlus for Linux

Need a quick edit on the go? Download TablePlus for iOS

TablePlus in Dark mode