Quick Intro to the event_scheduler System Variable in MySQL

In MySQL, the event_scheduler system variable is used to start and stop the Event Scheduler, as well as enable or disable it.

At runtime we can set the value to ON or OFF, and we can check the current value of the variable. We can also disable the Event Scheduler at server startup, but we can’t do this at runtime. However, we can still check the event_scheduler variable to see whether it’s enabled or disabled.

Check the Current Value

We can check the current value of the event_scheduler variable with a SELECT statement:

SELECT @@global.event_scheduler;

Result:

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

The event_scheduler system variable is a global variable, and so I prefixed it with global.

Set the Value

We can set the value of the event_scheduler variable with a SET statement. We have several options for doing this. All of the following are equivalent, and will result in the Event Scheduler being turned on:

SET GLOBAL event_scheduler = ON;
SET @@GLOBAL.event_scheduler = ON;
SET GLOBAL event_scheduler = 1;
SET @@GLOBAL.event_scheduler = 1;

The values 1 and ON mean the same thing. Likewise with 0 and OFF.

All of the following turn it off:

SET GLOBAL event_scheduler = OFF;
SET @@GLOBAL.event_scheduler = OFF;
SET GLOBAL event_scheduler = 0;
SET @@GLOBAL.event_scheduler = 0;

All of the above specify event_scheduler as a global variable. This is required. If we try to set it without specifying it as a global variable, we’ll get an error:

SET @@event_scheduler = OFF;

Result:

ERROR 1229 (HY000): Variable 'event_scheduler' is a GLOBAL variable and should be set with SET GLOBAL