Close

2023-07-21

How to Easily List Scheduled Events in MySQL

How to Easily List Scheduled Events in MySQL

We can use the SHOW EVENTS statement to list MySQL’s scheduled events by SQL. The syntax for the SHOW EVENTS statement is as follows:

SHOW EVENTS [IN schema_name] [LIKE pattern]

The schema_name parameter is optional. If you specify a schema name, the SHOW EVENTS statement will only list the scheduled events in that schema. The pattern parameter is also optional. If you specify a pattern, the SHOW EVENTS statement will only list the scheduled events whose names match the pattern.

For example, the following SQL statement will list all of the scheduled events in the my_database Schema:

SHOW EVENTS IN my_database;

The following SQL statement will list all of the scheduled events whose names start with the word backup:

SHOW EVENTS LIKE 'backup%';

The SHOW EVENTS statement will return a table of information about each scheduled event. The table will include the following columns:

  • EVENT_NAME: The name of the event.
  • DEFINER: The user who created the event.
  • TIME_ZONE: The time zone that the event is scheduled in.
  • EVENT_BODY: The SQL statement that the event executes.
  • EVENT_TYPE: The type of event (one-time or recurring).
  • EXECUTE_AT: The date and time that the event is scheduled to execute.
  • INTERVAL_VALUE: The interval between event executions for recurring events.
  • INTERVAL_FIELD: The interval field for recurring events.
  • STARTS: The start date and time for recurring events.
  • ENDS: The end date and time for recurring events.
  • STATUS: The status of the event (enabled or disabled).