导航

mysql设置定时任务

Posted on 2016-01-10 11:21  ggzone  阅读(152)  评论(0编辑  收藏  举报

–查看时间调度器是否开启

SHOW VARIABLES LIKE 'event_scheduler';
SELECT @@event_scheduler;

–开启时间调度器

SET GLOBAL event_scheduler = ON;

–创建定时任务

create event if not exists e_test
on schedule every 30 second
on completion preserve
do call day_update();
CREATE EVENT if not exists event_day_update
ON SCHEDULE EVERY 1 DAY STARTS '2016-01-04 00:20:00'
ON COMPLETION PRESERVE
ENABLE
DO call day_update();  --day_update是存储过程

–开启定时任务

alter event event_day_update ON COMPLETION PRESERVE ENABLE;

–关闭定时任务

alter event event_day_update ON COMPLETION PRESERVE DISABLE;