MySQL supports the creation of timed tasks, requiring the MySQL server to start scheduled task scheduling.
1. Check if scheduled task execution is turned on
SHOW VARIABLES like ' Event_scheduler '; Off means no open
2. Turn on timed tasks
SET GLOBAL event_scheduler = on;
Or
Add Event_scheduler = 1 in the my.cnf file
3. Writing timed Tasks
Syntax rules:
CREATE EVENT [IF not EXISTS] Event_Name//Specify name
On SCHEDULE SCHEDULE//Specify task scheduling rules
On completion [NOT] PRESERVE//Specifies whether the task is executed one time, or multiple times, not given when not, is executed one time, and executes multiple times by default
[disable| Enable]//Specify whether the task is active, activate by default enable
[COMMENT ' COMMENT ']//specify annotations, comments
Do sqlstament//Specify the specific execution SQL
Schedule rules:
at TIMESTAMP [+ INTERVAL INTERVAL] | Every INTERVAL [starts TIMESTAMP] [ENDS TIMESTAMP]
Interval rules:
Quantity {Year | QUARTER | MONTH | Day | HOUR | MINUTE | WEEK | SECOND | Year_month | Day_hour | Day_minute | Day_second | Hour_minute | Hour_second | Minute_second}
Quantity to Digital
4. Case studies
Use test;
CREATE TABLE ' e_t ' (
' Timeline ' timestamp not NULL DEFAULT current_timestamp on UPDATE current_timestamp
) Engine=myisam DEFAULT Charset=utf8;
CREATE EVENT Event_insert_et on SCHEDULE every 1 SECOND does insert into test.e_t VALUES (current_timestamp);
[DB]-MySQL Create timed task