mysql on schedule_mysql的定时执行任务

0:查看事件的状态show variables like %event_sche%;-- 查询mysql的事件的状态,默认是OFF启动事件set global event_scheduler1;-- 设置事件为启动状态

0:查看事件的状态

show variables like '%event_sche%';-- 查询mysql的事件的状态,默认是OFF

启动事件

set global event_scheduler=1;-- 设置事件为启动状态,数据库重启后失效

1:创建存储过程

在mysql workbench工具的数据库中创建存储过程的方法是选择“stored procedures”,创建一个存储过程

CREATE PROCEDURE `teacher_test` ()

BEGIN

insert into teacher(tid,tname,tsex) values(1,'张三','男');

END

10:创建定时事件

create event second_event #second_event表示事件的名称

on schedule every 5 second #每隔5秒执行一次

on completion preserve disable #创建后不立即执行

do call teacher_test(); #调用存储过程

11: 常见的定时时间函数

周期执行–关键字 EVERY

单位有:second,minute,hour,day,week(周),quarter(季度),month,year

如:

on schedule every 1 second //每秒执行1次

on schedule every 2 minute //每两分钟执行1次

on schedule every 3 day //每3天执行1次

在具体某个时间执行–关键字 AT

如:

on schedule at current_timestamp()+interval 5 day //5天后执行

on schedule at current_timestamp()+interval 10 minute //10分钟后执行

on schedule at '2016-10-01 21:50:00' //在2016年10月1日,晚上9点50执行

在某个时间段执行–关键字STARTS ENDS

如:

on schedule every 1 day starts current_timestamp()+interval 5 day ends current_timestamp()+interval 1 month //5天后开始每天都执行执行到下个月底

on schedule every 1 day ends current_timestamp()+interval 5 day //从现在起每天执行,执行5天

100:开启和关闭时间

alter event second_event on completion preserve enable;-- 开启定时任务

alter event second_event on completion preserve disable;-- 关闭定时任务

发布者:admin,转转请注明出处:http://www.yc00.com/web/1755003074a5225663.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信