MySQL 创建定时器

这段脚本的大致意思就是每日执行一次,删除一个月之前的数据

CREATE EVENT delete_t_error_log_data_event
ON SCHEDULE
    EVERY 1 DAY  
    STARTS CURRENT_TIMESTAMP  
DO
BEGIN
    DECLARE target_date DATE; 
    SET target_date = DATE_SUB(CURRENT_DATE, INTERVAL 1 MONTH);  
    SET @delete_query = CONCAT('DELETE FROM t_error_log WHERE create_time < "', target_date, '" LIMIT 50000;' ); 
    PREPARE stmt FROM @delete_query;   
    EXECUTE stmt;
    DEALLOCATE PREPARE stmt;
END;

 

posted @ 2024-02-02 16:13  Mr_Xul  阅读(18)  评论(0编辑  收藏  举报