1.检查数据库是否开启
navicat 执行:**SHOW VARIABLES LIKE 'event_scheduler';**
2.如果没有开启泽需要执行:**SET GLOBAL event_scheduler = ON;**
3.添加任务
DELIMITER $$
DROP EVENT IF EXISTS deletecase;
CREATE EVENT deletecase
ON SCHEDULE EVERY 300 SECOND
ON COMPLETION PRESERVE
DO BEGIN
delete from test WHERE TO_DAYS(now())-TO_DAYS(CREATE_TIME)>180;
END$$
DELIMITER ;
4.查看任务状态:
SELECT * FROM information_schema.EVENTS
网友评论