MySQL timed tasks are introduced from version 5.1, also known as temporary triggers, but unlike normal triggers, a normal trigger is an event triggered by manipulating every row of data in a data table, and it is triggered by a point in time or time period
First look at its syntax:
DELIMITER $$--SET GLOBAL Event_scheduler = on$$--Required for event to execute and not createCREATE /*[definer = {User | Current_User}]*/EVENT ' event1 ' onSCHEDULE/*Uncomment the example below you want*/ --scheduleexample 1:run once --At ' Yyyy-mm-dd hh:mm. SS '/current_timestamp {+ INTERVAL 1 [hour| month| week| day| Minute| ...] } --scheduleexample 2:run at intervals forever after creation --every 1 [hour| month| week| day| Minute| ...] --scheduleexample 3:specified start time, end time and interval for execution /*every 1 [hour| month| week| day| Minute| ...] Starts current_timestamp/' Yyyy-mm-dd hh:mm. SS ' {+ INTERVAL 1[hour| month| week| day| Minute| ...] } ENDS current_timestamp/' Yyyy-mm-dd hh:mm. SS ' {+ INTERVAL 1 [hour| month| week| day| Minute| ...] } *//*[on completion [NOT] preserve][enable | Disable][comment ' COMMENT ']*/ DoBEGIN(sql_statements)END$ $DELIMITER;
Basically through the above syntax to understand how to use, the following for each way can write a little chestnut
1, Trigger (execute once) at a certain point in time:
DELIMITER $$CREATEEVENT ' bdhp '. ' E_e1 ' onSCHEDULE/*Execute only once*/ /*At ' 2015-02-03 16:07.00 '*//*a certain point in time*/ /*At ' 2015-02-03 16:47.20 ' + INTERVAL second*//*A point in time + a period of time*/ atCurrent_timestamp+INTERVAL +SECOND/*current point in time + period of time*/ DoBEGIN INSERT intoT_sys_log (SN)VALUES('55555'); END$ $DELIMITER;
2, per cycle, infinite number of times
DELIMITER $$ CREATE EVENT ' e_e2 'on SCHEDULE 1 minutedo BEGIN INSERT into T_sys_log (SN)VALUES('55555' ); END $ $DELIMITER;
3, in a certain time period, by the cycle execution (ends does not write is to start from a point of execution)
DELIMITER $$CREATEEVENT ' e_e3 ' onSCHEDULE every1SECOND startsCurrent_timestampENDS'2015-02-03 16:15.00' DoBEGIN INSERT intoT_sys_log (SN,user_name)VALUES('Test','ttt-55'); END$ $DELIMITER;
mysql-Scheduled Tasks