--存儲過程 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