Mysql Event Not Working
Verify if the event_scheduler is On - execute the following command:
SHOW PROCESSLIST;
It'll output a table/entries, you must look for an entry with User event_scheduler
, and Command Daemon
:
Id User Host db Command Time State Info
22870 event_scheduler localhost \N Daemon 23 Waiting for next activation \N
OR, you can also verify using the following command:
SELECT @@global.event_scheduler;
The result should be ON
, otherwise set it off (will get 0
for the command), as stated in the next section.
If you don't have any such entry (as above), you may start the event scheduler using the following command:
SET GLOBAL event_scheduler = ON;
Once done, you can verify if it has been executed properly using the SHOW PROCESSLIST
command, as mentioned above.
For those wondering how to enable it by default at startup, add the following to your config file (my.ini, my.cnf):
#Event scheduler can be set to 1 (On), 0 (Off), or Disabled
event_scheduler=1
Restart of the service is required in this case, so if you want minimal disruption, add this to the config file, and then run the SQL:
SET GLOBAL event_scheduler = ON;
That way, it will run for the current process, and if the server is restarted it will still work.
Note that this doesn't work if the event_scheduler was set to disabled. In that case the only option is to restart the service.
Events are run by the scheduler, which is not started by default.
Using SHOW PROCESSLIST
is possible to check whether it is started. If not, run the command
SET GLOBAL event_scheduler = ON;
to run it.