mysql使用存储过程和event定期删除
-- 创建存储过程
DELIMITER //
CREATE PROCEDURE del_data()
BEGIN
DELETE FROM t_route_status WHERE route_date < DATE_SUB(CURDATE(),INTERVAL 7 DAY);
END ;
-- 创建事件
CREATE event del_event
ON SCHEDULE
EVERY 1 DAY
STARTS '2019-03-08 06:00:00'
ON COMPLETION PRESERVE ENABLE
DO CALL del_data();
-- 查看event_scheduler定时任务事件是否开启;
SHOW VARIABLES LIKE '%sche%';
-- 开启全局事件
SET GLOBAL event_scheduler=ON;
详情请参考:
https://www.2cto.com/database/201402/278096.html