简体   繁体   English

MySQL事件未按计划执行任务?

[英]MySQL Event not performing task as per scheduled?

I have created event logging as root user and GLOBAL event_scheduler is also ON My event procedure query is: 我已经以root用户身份创建了事件日志记录,并且GLOBAL event_schedulerGLOBAL event_scheduler ON我的事件过程查询为:

DELIMITER $$

CREATE 
    EVENT `near_end_warranty` 
    ON SCHEDULE EVERY 1 HOUR
    DO BEGIN

        DECLARE numrow int;
        SELECT COUNT(id) FROM equipments WHERE TIMESTAMPDIFF(WEEK,NOW(),warranty_end_date)<5 AND TIMESTAMPDIFF(WEEK,NOW(),warranty_end_date)>0 INTO numrow;

        IF numrow>0 THEN
        INSERT INTO notifications (eq_id,start_date,end_date,name,type,message,created_by,modified_by,created_on,modified_on)
        SELECT eq_id,warranty_start_date,warranty_end_date,'warranty','ending soon','warranty ends soon for','System','System',NOW(),NOW()
        FROM equipments WHERE TIMESTAMPDIFF(WEEK,NOW(),warranty_end_date)<5 AND TIMESTAMPDIFF(WEEK,NOW(),warranty_end_date)>0;
        END IF;

    END $$

DELIMITER ;

and my event status is: 我的活动状态是:

Db:db_medisup
Name:near_end_warranty
Definer:root@localhost
Time zone:SYSTEM
Type:RECURRING
Execute at:NULL
Interval value:1
Interval field:HOUR
Starts:2015-05-08 07:11:09
Ends:NULL
Status:ENABLED
Originator:1
character_set_client:utf8
collation_connection:utf8_general_ci
Database Collation:latin1_swedish_ci

I am trying to get multiple rows from equipment table as per condition and insert into notifications table on hourly basis.I created this event on 07:11,Its 9:52 already and hasn't inserted any rows to notification table yet.warranty_end date:2015-05-20 on two rows of equipment table and today's date is 2015-05-08,so two rows must be added to notification table.What may be the problem here? 我试图根据条件从设备表中获取多行,并每小时插入一次通知表。我在07:11创建了此事件,它的时间是9:52,并且尚未在通知表中插入任何行。warranty_enddate :2015-05-20在设备表的两行上,今天的日期是2015-05-08,因此必须在通知表中添加两行。这里可能是什么问题?

我实际上找到了确切的问题,表的字段名称和查询中有一些错误,我现在解决了它,一切运行正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM