欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Mysql存储过程--大于十分钟执行

程序员文章站 2022-05-01 16:43:14
--存储过程 DELIMITER | DROP PROCEDURE IF EXISTS update_tatus | CREATE PROCEDURE update_status() BEGIN IF exists (select id from status_his where status = ... ......
--存储过程
delimiter |
drop procedure if exists update_tatus |
create procedure update_status()
begin
    if exists (select id from status_his where status = 2 and createtime <= now()-interval 10 minute) then
            update status_his set status = 4
            where id in (select d.id from (select d.id from status_his d where status = 2 and createtime <= now()-interval 10 minute ) d)and status = 2;
    end if;
end 
 |delimiter;

--定时器  
    delimiter //
    create event  update_status
    on schedule every 300 second  do
    begin
    call update_status();
    end //
    delimiter;

--启动定时器
    alter event update_status on  
    completion preserve enable;

--查询是否开启event
show variables like '%event_scheduler%';

--开启event
set global event_scheduler =1;


--删除定时器
drop event update_status