2 Ways to View an Event’s Comment in MySQL

When we create a scheduled event in MySQL, we have the option of adding a comment to the event. This comment can be a string of up to 64 characters. We have a couple of options when it comes to viewing the comment of an existing event.

Option 1: The Information Schema

We can query the information schema to see the comment of existing events. In particular, we can query the information_schema.events view. This view has a column called EVENT_COMMENT that holds the comment for the event:

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 |
+-----------------------------------------+

In this example I checked the comment for an event called insert_timestamp in the krankykranes database. The event was created with a comment, and so we can see that comment in the result set.

If an event doesn’t have a comment, then this column will be empty – it will look like this:

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

Option 2: The SHOW CREATE EVENT Statement

Another way of seeing an event’s comment is with the SHOW CREATE EVENT statement. This returns information about the event, along with the event’s COMMENT clause, if any.

Therefore, we can run the following query for the above 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 (in the Create_Event column).

If the event doesn’t have a comment, there would be no COMMENT clause in there.