2

设置Mysql自动定时删除xxljob的日志数据

 1 month ago
source link: https://bajie.dev/posts/20240320-mysql_delete_xxllog/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

设置Mysql自动定时删除xxljob的日志数据

2024-03-20 1 分钟阅读

xxl-job的日志数据实在是太大了,压根就没有清理过,设置一个定时任务来定时删除无用的废数据吧:

首先要确认定时任务开关已经打开了

show variables like %event_sche%;
On表示开启

然后到指定的库下,use k8s_xxl_job

CREATE EVENT delete_k8s_xxl_log
ON SCHEDULE EVERY 1 DAY
DO
DELETE FROM xxl_job_log WHERE trigger_time < CURRENT_TIMESTAMP - INTERVAL 7 DAY;

保留今天的数据,以及前7天的老数据。

查看以及编辑定时任务的命令:

#查看
show events;

#查看细节
SHOW CREATE EVENT delete_k8s_xxl_log

#编辑
ALTER EVENT delete_k8s_xxl_log
ON SCHEDULE EVERY 1 DAY
DO
BEGIN
    -- 在这里添加你想要执行的操作
END;

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK