SHOW VARIABLES LIKE ‘event_scheduler’;
Value为ON则已打开,OFF则关闭
如果是OFF,就先打开:
SET GLOBAL event_scheduler = ON;
然后创建我们想要的定时器
DELIMITER $$
DROP EVENT IF EXISTS deletefol_bigorders_rfm;
CREATE EVENT deletefol_bigorders_rfm
ON SCHEDULE EVERY 1 DAY STARTS DATE_ADD(DATE_ADD(CURDATE(), INTERVAL 1 DAY), INTERVAL 1 HOUR)
ON COMPLETION PRESERVE
DO BEGIN
delete from fol_bigorders_rfm;
END$$
DELIMITER ;
DELIMITER $$
DROP EVENT IF EXISTS deletefol_bigorders_rfm;
CREATE EVENT deletefol_bigorders_rfm
ON SCHEDULE EVERY 1 MINUTE
ON COMPLETION PRESERVE
DO BEGIN
delete from fol_bigorders_rfm;
END$$
DELIMITER ;
DELIMITER $$
DROP EVENT IF EXISTS deletefol_bigorders_rfm;
CREATE EVENT deletefol_bigorders_rfm
ON SCHEDULE EVERY 1 HOUR
ON COMPLETION PRESERVE
DO BEGIN
delete from fol_bigorders_rfm;
END$$
DELIMITER ;
DELIMITER $$
DROP EVENT IF EXISTS deletefol_bigorders_rfm;
CREATE EVENT deletefol_bigorders_rfm
ON SCHEDULE EVERY 3 DAY STARTS NOW()
ON COMPLETION PRESERVE
DO BEGIN
delete from fol_bigorders_rfm;
END$$
DELIMITER ;
DELIMITER $$
DROP EVENT IF EXISTS deletefol_bigorders_rfm;
CREATE EVENT deletefol_bigorders_rfm
ON SCHEDULE EVERY 5 MONTH STARTS DATE_ADD(DATE_ADD(DATE_SUB(CURDATE(),INTERVAL DAY(CURDATE())-1 DAY), INTERVAL 1 MONTH),INTERVAL 1 HOUR)
ON COMPLETION PRESERVE
DO BEGIN
delete from fol_bigorders_rfm;
END$$
DELIMITER ;
DELIMITER $$
DROP EVENT IF EXISTS deletefol_bigorders_rfm;
CREATE EVENT deletefol_bigorders_rfm
ON SCHEDULE EVERY 3 QUARTER STARTS DATE_ADD(DATE_ADD(DATE( CONCAT(YEAR(CURDATE()),'-',ELT(QUARTER(CURDATE()),1,4,7,10),'-',1)),INTERVAL 1 QUARTER),INTERVAL 2 HOUR)
ON COMPLETION PRESERVE
DO BEGIN
delete from fol_bigorders_rfm;
END$$
DELIMITER ;
DELIMITER $$
DROP EVENT IF EXISTS deletefol_bigorders_rfm;
CREATE EVENT deletefol_bigorders_rfm
ON SCHEDULE EVERY 1 YEAR STARTS DATE_ADD(DATE(CONCAT(YEAR(CURDATE()) + 1,'-',1,'-',1)),INTERVAL 3 HOUR)
ON COMPLETION PRESERVE
DO BEGIN
delete from fol_bigorders_rfm;
END$$
DELIMITER ;
select * from deletefol_bigorders_rfm.event;
DROP event deletefol_bigorders_rfm.event;
ALTER EVENT deletefol_bigorders_rfm.event DISABLE;
ALTER EVENT deletefol_bigorders_rfm.event ENABLE;
DROP EVENT [IF EXISTS] deletefol_bigorders_rfm.event;
ALTER EVENT deletefol_bigorders_rfm.event RENAME TO deletefol_bigorders_rfm_new COMMENT '重命名事件';
SHOW CREATE EVENT deletefol_bigorders_rfm.event;