mysql中的事件调度程序无法正常工作

时间:2013-12-02 13:27:04

标签: mysql

我告诉下面提到的调度程序,它每分钟删除一些数据,其date_created是四天回到当前日期,但是当文件在mysql中导入时删除一次数据,但之后对我不起作用。请告诉我调度程序有什么问题。

use mydatabase;
DROP EVENT IF EXISTS  noti_event ;
SET GLOBAL event_scheduler = OFF;
SET GLOBAL event_scheduler = ON;
create EVENT IF NOT EXISTS noti_event ON SCHEDULE EVERY 1 MINUTE STARTS CURDATE() + '12:00:00'

DO
   SET FOREIGN_KEY_CHECKS=0;
   DELETE FROM user_noti WHERE noti_id in (Select id from noti where date_created <= DATE_SUB(NOW(), INTERVAL 4 DAY));
   DELETE FROM noti_read_by WHERE noti_id in (Select id from noti where date_created <= DATE_SUB(NOW(), INTERVAL 4 DAY));
   DELETE FROM associated_add WHERE id  in (Select id from noti where date_created <= DATE_SUB(NOW(), INTERVAL 4 DAY));
   DELETE FROM noti WHERE date_created <= DATE_SUB(NOW(), INTERVAL 4 DAY) ;
   SET FOREIGN_KEY_CHECKS=1;
;

1 个答案:

答案 0 :(得分:1)

您需要设置ON COMPLETION PRESERVE选项,例如 -

CREATE EVENT event1
  ON SCHEDULE EVERY '1' MINUTE
  STARTS CURRENT_TIMESTAMP
  ON COMPLETION PRESERVE
  DO 
BEGIN
END