欢迎投稿

今日深度:

Mysql存储过程--大于十分钟执行,执行存储过程的命令

Mysql存储过程--大于十分钟执行,执行存储过程的命令


--存储过程
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

 

www.htsjk.Com true http://www.htsjk.com/Mysql/35309.html NewsArticle Mysql存储过程--大于十分钟执行,执行存储过程的命令 -- 存储过程 DELIMITER | DROP PROCEDURE IF EXISTS update_tatus | CREATE PROCEDURE update_status() BEGIN IF exists ( select id from status_his where status = 2 and cre...
相关文章
    暂无相关文章
评论暂时关闭