Index

  1. Home
  2. Docs
  3. Index
  4. Query Builder
  5. Scheduled queries

Scheduled queries

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
Was this article helpful to you? Yes No

Leave a Reply

Your email address will not be published.

16 + five =