If you’re getting an error that reads “ERROR 1229 (HY000): Variable ‘event_scheduler’ is a GLOBAL variable and should be set with SET GLOBAL” in MySQL, it’s probably because you’re trying to set the event_scheduler
system variable, but you’re not specifying it as a global variable.
The event_scheduler
variable is a global variable and so we must specify it as a global variable.
To fix this issue, specify it as a global variable when setting it’s value.
Example of Error
Here’s an example of code that produces the error:
SET @@event_scheduler = ON;
Result:
ERROR 1229 (HY000): Variable 'event_scheduler' is a GLOBAL variable and should be set with SET GLOBAL
The error message is reasonably self explanatory. We got the error because the event_scheduler
variable is a global variable but we didn’t specify it as such.
Solution
The solution is easy – specify the variable as a global variable. We have a couple of ways of doing this.
One way is like this:
SET GLOBAL event_scheduler = ON;
Result:
Query OK, 0 rows affected (0.00 sec)
This time there was no error.
Another way to do it is like this:
SET @@GLOBAL.event_scheduler = ON;
Result:
Query OK, 0 rows affected (0.00 sec)
Both methods set the variable as a global variable.
We can also set it to 1
or 0
, which is the same as setting it to ON
and OFF
respectively.