每个月两个日期之间的MySQL事件

时间:2018-10-25 08:04:56

标签: mysql

我需要在每月的第二天到第八天之间运行MySQL事件。最好的方法是什么。

第一个选项:

DELIMITER $$
CREATE EVENT createmyevent
ON SCHEDULE EVERY 1 MONTH STARTS '2018-10-02 06:00:00' ENDS '2018-10-08 06:00:00'
ON COMPLETION PRESERVE
DO
.... Codes
END;$$
DELIMITER ;

第二个选项:

DELIMITER $$
CREATE EVENT createmyevent
ON SCHEDULE EVERY 1 MONTH STARTS '2018-10-02 05:30:00'
DO
BEGIN
SELECT  @dow    := dayofmonth(NOW())
,       @oclock := hour(NOW());`

IF (@dow = 2 AND @oclock = 6) 
OR (@dow = 3 AND @oclock = 6) 
OR (@dow = 4 AND @oclock = 6) 
OR (@dow = 5 AND @oclock = 6) 
OR (@dow = 6 AND @oclock = 6) 
OR (@dow = 7 AND @oclock = 6) 
OR (@dow = 8 AND @oclock = 6) 
THEN 
.... Codes 
END IF;
END$$
DELIMITER ;

0 个答案:

没有答案