It is possible to use MySQL events to execute queries at regular intervals. Conceptually, this is similar to the Unix crontab and the Windows Task Scheduler. The example below truncates my demo table and adds five rows every 60 seconds.
CREATE EVENT demo_event
ON SCHEDULE EVERY 60 SECOND DO
BEGIN
DECLARE i INTEGER;
SET i = 0;
TRUNCATE TABLE demo;
WHILE i < 5 DO
INSERT INTO demo VALUES (i);
SET i = i + 1;
END WHILE;
END
/
Notes #
- The event scheduler needs to run to execute events (check with show processlist)
- Read more about the MySQL event scheduler