1. 程式人生 > >Mysql 計劃任務

Mysql 計劃任務

-- 設定
show variables like '%sche%';
set global event_scheduler =1;

-- Start儲存過程 
drop PROCEDURE if exists test;
CREATE PROCEDURE test() 
BEGIN 

insert into `user`
values (1,2,3,4);

END
-- End儲存過程

-- Start 定時任務

drop EVENT if exists e_test ;
CREATE event e_test 
-- 1 每天凌晨3點
ON SCHEDULE EVERY 1 DAY STARTS DATE_ADD(DATE_ADD(CURDATE(), INTERVAL 1 DAY), INTERVAL 2 HOUR)
-- 2 每10秒跑
-- on schedule every 10 second 
on completion preserve 
do call test();


alter event e_test ON 
COMPLETION PRESERVE ENABLE;

-- End 定時任務