MySQL event scheduler

Pretty cool thing, the mysql event scheduler. Cron jobs inside MySQL.

The MySQL event scheduler is off by default, you can switch it on by calling
SET GLOBAL event_scheduler = ON;

You could event do some automatic drop table if you like 😉

Here’s a short example:

DELIMITER ;;

DROP EVENT IF EXISTS my_event;;

SET GLOBAL event_scheduler = ON;;

CREATE EVENT my_event
ON SCHEDULE EVERY 1 MINUTE
DO
CALL add_new_partition();
END;;

DELIMITER ;

Call
SHOW PROCESSLIST;
and you see the event happily counting seconds until next execution:

MySQL event scheduler

This entry was posted in mysql. Bookmark the permalink.

Leave a Reply