Created
March 1, 2017 08:14
-
-
Save anonymous/f047fa90d9b1ef27a2fca9b17d25748a to your computer and use it in GitHub Desktop.
The MySQL Event Scheduler manages the scheduling and execution of events, that is, tasks that run according to a schedule.
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
/* | |
Original Idea: @josuebasurto | |
Reference: https://dev.mysql.com/doc/refman/5.7/en/event-scheduler.html | |
*/ | |
-- Use certain database | |
use mydatabase; | |
-- Show all events from a database | |
show events from mydatabase; | |
-- Short version | |
show events; | |
-- Detailed version | |
SELECT * FROM INFORMATION_SCHEMA.events; | |
-- Friendly Version | |
SELECT EVENT_NAME, EVENT_DEFINITION, EXECUTE_AT, status, LAST_EXECUTED FROM INFORMATION_SCHEMA.events; | |
--Check Original Data | |
select * from latabla; | |
--Create an event that will run | |
CREATE EVENT FIRSTEVENT ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 1 MINUTE DO | |
update latabla set descripcion = '1'; | |
-- Add comments to identify | |
CREATE EVENT SECONDEVENT ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 1 MINUTE COMMENT 'THIS IS A COMMENT' DO | |
update latabla set descripcion = '2'; | |
-- Drop events | |
drop event FIRSTEVENT; | |
drop event SECONDEVENT; | |
-- Check current Timestamp of the server | |
select current_timestamp; | |
-- Turn on scheduler! Important | |
SET GLOBAL event_scheduler = ON; | |
-- Turn it off | |
SET GLOBAL event_scheduler = OFF; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment