3 Ways to Check the Event Scheduler Status in MySQL

In MySQL we can create events that run on a specified schedule. But events will only run if the Event Scheduler is on. If the Event Scheduler is off or disabled, then such events won’t run as scheduled.

Therefore if we create any events on the server, it’s a good idea to check whether the Event Scheduler is on or not.

Here are three options for doing this using SQL.

Check the event_scheduler Variable

There’s a global system variable called event_scheduler that enables or disables, and starts or stops the Event Scheduler. This variable is set to either ON, OFF, or DISABLED.

We can check this variable with a SELECT statement:

SELECT @@global.event_scheduler;

Result:

+--------------------------+
| @@global.event_scheduler |
+--------------------------+
| ON                       |
+--------------------------+

In this case, the Event Scheduler is enabled, and it’s set to ON. That means events will run as scheduled.

The SHOW VARIABLES Statement

Another way to do it is with the SHOW VARIABLES statement:

SHOW VARIABLES WHERE variable_name = 'event_scheduler';

Result:

+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| event_scheduler | ON    |
+-----------------+-------+

Here I used the WHERE clause to narrow the results to just the Event Scheduler. The output shows that it’s on as expected.

The SHOW PROCESSLIST Statement

Events are executed by a special event scheduler thread. When the Event Scheduler is on, an event scheduler thread will be running. Therefore it’s possible to figure out whether or not the Event Scheduler is on by looking at the MySQL process list.

The MySQL process list indicates the operations currently being performed by the set of threads executing within the server. When the Event Scheduler is enabled and on, it appears as a thread in the process list. When it’s disabled or off, it doesn’t appear.

Here’s an example:

SHOW PROCESSLIST;

Result:

+----+-----------------+-----------------+------+---------+-------+------------------------+------------------+
| Id | User            | Host            | db   | Command | Time  | State                  | Info             |
+----+-----------------+-----------------+------+---------+-------+------------------------+------------------+
|  5 | event_scheduler | localhost       | NULL | Daemon  | 45721 | Waiting on empty queue | NULL             |
|  8 | root            | localhost:49468 | NULL | Sleep   | 45365 |                        | NULL             |
|  9 | root            | localhost:49470 | NULL | Sleep   | 45365 |                        | NULL             |
| 10 | root            | localhost:49472 | NULL | Sleep   | 45365 |                        | NULL             |
| 11 | root            | localhost       | NULL | Query   |     0 | init                   | SHOW PROCESSLIST |
+----+-----------------+-----------------+------+---------+-------+------------------------+------------------+

In this case an event scheduler thread appears in the output, which means that the Event Scheduler is enabled and it’s on.

If it didn’t appear here, then we’d know that it’s either set to OFF or disabled altogether.