欢迎光临
有事儿没事儿分享一下!

MySQL如开启定时任务

MySQL开启定时任务的步骤如下:

1.检查event事件是否开启

show variables like '%sche%';

2022-05-08_200412.jpg

没开启的话,执行命令开启:

set global event_scheduler=1;

2.创建存储过程

创建一个名为update_leave_records的存储过程。

CREATE PROCEDURE update_leave_records() UPDATE sys_leave_records AS t1,
sys_biz_process AS t2 
SET t1.process_status = t2.process_status,
t1.remark = t2.remark,
t1.update_time = sysdate() 
WHERE
    t1.biz_id = t2.biz_id 
    AND t2.biz_id IN (
    SELECT
        p.biz_id 
    FROM
        sys_biz_process AS p
        LEFT JOIN sys_process_def AS d ON p.process_def_id = d.def_id 
    WHERE
        d.def_type = 'ASK_FOR_LEAVE' 
    AND (
    p.update_time > DATE_SUB( NOW(), INTERVAL 30 MINUTE )));

3.创建定时任务

CREATE EVENT
IF NOT EXISTS leave_monitor ON SCHEDULE EVERY 120 SECOND ON COMPLETION preserve

DO CALL update_leave_records(); 

4.查看定时任务

select * from  mysql.event;

参考:

  1. https://blog.csdn.net/wq1039822486/article/details/79637168;
赞(0)
未经允许禁止转载:四个空格 » MySQL如开启定时任务

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址