Remove the Comment from an Event in MySQL

When we create a scheduled event in MySQL we have the option of using the COMMENT clause to add a comment to the event. Comments can be a handy addition that help explain what the event does, why it was created, etc.

So it’s probably quite rare that we would want to remove the comment from an event. But in the event that we do (pun intended!), we can simply update the event with a blank comment.

Example

Suppose we create an event like this:

CREATE EVENT insert_timestamp
    ON SCHEDULE
        EVERY 1 MONTH
    COMMENT 'Insert timestamp into table every month'
    DO
        INSERT INTO EventTest ( EventTimestamp, InsertedBy ) 
            VALUES (NOW(), 'insert_timestamp');

The line starting with COMMENT is the comment clause. That’s what creates the comment. The COMMENT clause accepts a string up to 64 characters. In other words, our comments can be a maximum of 64 characters.

We can query the information schema to verify that the event was created with the comment:

SELECT 
    event_comment
FROM information_schema.events
WHERE event_schema = 'krankykranes'
AND event_name = 'insert_timestamp';

Result:

+-----------------------------------------+
| EVENT_COMMENT |
+-----------------------------------------+
| Insert timestamp into table every month |
+-----------------------------------------+

We can also use the SHOW CREATE EVENT statement to see the code that would be used to recreate the event:

SHOW CREATE EVENT insert_timestamp;

Result:

+------------------+-------------------------------------------------------------------------------------------------------------------------------------------+-----------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+--------------------+
| Event | sql_mode | time_zone | Create Event | character_set_client | collation_connection | Database Collation |
+------------------+-------------------------------------------------------------------------------------------------------------------------------------------+-----------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+--------------------+
| insert_timestamp | ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ALLOW_INVALID_DATES,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION | SYSTEM | CREATE DEFINER=`root`@`localhost` EVENT `insert_timestamp` ON SCHEDULE EVERY 1 MONTH STARTS '2024-04-11 08:39:40' ON COMPLETION NOT PRESERVE ENABLE COMMENT 'Insert timestamp into table every month' DO INSERT INTO EventTest ( EventTimestamp, InsertedBy )
VALUES (NOW(), 'insert_timestamp') | utf8mb4 | utf8mb4_0900_ai_ci | utf8mb4_0900_ai_ci |
+------------------+-------------------------------------------------------------------------------------------------------------------------------------------+-----------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+--------------------+

We can see the COMMENT clause after the ENABLE clause.

Remove the Comment

We can remove that comment by updating the event with a blank comment. By “blank comment” I mean an empty string:

ALTER EVENT insert_timestamp
    COMMENT '';

Now let’s query the information schema again:

SELECT 
event_comment
FROM information_schema.events
WHERE event_schema = 'krankykranes'
AND event_name = 'insert_timestamp';

Result:

+---------------+
| EVENT_COMMENT |
+---------------+
| |
+---------------+

There’s no comment in the event any more.

We can also use the SHOW CREATE EVENT statement to see the code that would be used to recreate the event:

SHOW CREATE EVENT insert_timestamp;

Result:

+------------------+-------------------------------------------------------------------------------------------------------------------------------------------+-----------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+--------------------+
| Event | sql_mode | time_zone | Create Event | character_set_client | collation_connection | Database Collation |
+------------------+-------------------------------------------------------------------------------------------------------------------------------------------+-----------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+--------------------+
| insert_timestamp | ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ALLOW_INVALID_DATES,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION | SYSTEM | CREATE DEFINER=`root`@`localhost` EVENT `insert_timestamp` ON SCHEDULE EVERY 1 MONTH STARTS '2024-04-11 08:32:30' ON COMPLETION NOT PRESERVE ENABLE DO INSERT INTO EventTest ( EventTimestamp, InsertedBy )
VALUES (NOW(), 'insert_timestamp') | utf8mb4 | utf8mb4_0900_ai_ci | utf8mb4_0900_ai_ci |
+------------------+-------------------------------------------------------------------------------------------------------------------------------------------+-----------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+--------------------+

There’s no comment in the event any more. There’s not even a COMMENT clause. If it had a comment, we’d see the COMMENT clause after the ENABLE clause.