mysql计划任务(轮询执行脚本)

mysql中进行定时执行一些任务,例如到了特定时间修改数据库中的字段。
1.查看事件是否开启

show variables like '%sche%'; 

2.off的话,则开启事件

set global event_scheduler =1;

3.创建存储过程

CREATE PROCEDURE book () 
update car_space SET  start_time =null , space_status=0 WHERE minute(timediff(now(),start_time))>15 and space_status=1;

4.创建事件event

create event if not exists e_book
on schedule every 30 second 
on completion preserve 
do call book(); 

解释:每30s执行一次存储过程book预定,对car_space表中的已经超过预定时间15min的数据进行恢复。
5.关闭event

alter event e_book ON 
COMPLETION PRESERVE DISABLE; 

6.开启事件

alter event e_book ON 
COMPLETION PRESERVE ENABLE; 
原文地址:https://www.cnblogs.com/wangxiaopei/p/8551258.html