mysql 的定时sql任务

1:先查看event 是否开启:

show variables like '%sche%';  如果是 OFF 的话 开启 EVENT: set global event_scheduler =1;


2: 创建存储过程:test

CREATE PROCEDURE test ()
BEGIN
update examinfo SET endtime = now() WHERE id = 14;
END; 


3:创建 Event t_test

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

每隔30秒将执行存储过程test,将当前时间更新到examinfo表中id=14的记录的endtime字段中去.


4:关闭事件:

alter event e_test ON
COMPLETION PRESERVE DISABLE; 


5: 开启事件任务:

alter event e_test ON
COMPLETION PRESERVE ENABLE; 


以上测试均成功,测试环境为mysql 5.4.2-beta-community mysql community server(GPL)


event_scheduler在mysql的config中设置为OFF有关。去mysql中将配置改为ON则就搞定了

你可能感兴趣的:(java,组件学习)