1 -- 创建存储过程 2 delimiter // 3 create procedure `prc_del`(IN date_inter int) COMMENT '自动删除7天前数据' 4 begin 5 delete from xly where (TO_DAYS(NOW()) - TO_DAYS(IR_LASTTIME))>=date_inter; 6 end// 7 8 -- 创建事件 9 DROP EVENT IF EXISTS clear_xly_event; 10 11 CREATE EVENT clear_xly_event 12 ON SCHEDULE EVERY 1 DAY 13 ON COMPLETION PRESERVE ENABLE 14 DO CALL prc_del(7);
每天定时删除七天前数据