Created
August 20, 2020 15:29
-
-
Save gbarreiro/6bef76fb637c8a8d8943a28fa71bfcd1 to your computer and use it in GitHub Desktop.
MySQL cheatsheet: scheduled event
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SET GLOBAL event_scheduler = ON; -- ensures that the MySQL event scheduler is on | |
-- One-time events | |
CREATE EVENT IF NOT EXISTS my_event | |
ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 12 HOUR -- the event will be run in 12h and then will be deleted | |
DO | |
DELETE * FROM Logs; -- something random | |
CREATE EVENT IF NOT EXISTS my_event | |
ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 24 MINUTE -- the event will be run in 24 minutes... | |
ON COMPLETION PRESERVE -- ... and then won't be deleted | |
DO | |
DELETE * FROM Logs; -- something random | |
-- Periodic event | |
CREATE EVENT IF NOT EXISTS my_event | |
ON SCHEDULE EVERY 1 HOUR -- runs every hour... | |
STARTS CURRENT_TIMESTAMP -- ... from now ... | |
ENDS CURRENT_TIMESTAMP + INTERVAL 1 DAY -- ... until tomorrow | |
DO | |
DELETE * FROM Logs; -- something random |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment