Specific usage details of scheduled tasks under mysql8

Mysql clears the table regularly

Set up event scheduler

SET GLOBAL event_scheduler=1;

Verify whether event_scheduler is turned on

show variables like '%event%'; #值为 ON 表明已开启
SHOW VARIABLES LIKE 'event_scheduler';

Insert image description here
Insert image description here

create event

DROP EVENT IF EXISTS e_delete_upvote; CREATE  EVENT e_delete_upvote    ON SCHEDULE EVERY 1 day STARTS DATE_ADD(current_date(),INTERVAL 1 DAY) ON COMPLETION PRESERVE ENABLE DO TRUNCATE TABLE dreamland.upvote; #说明: ON SCHEDULE EVERY 1 day 指定循环间隔为每天执行 STARTS date_add(concat(current_date(), ' 23:59:00'), interval 0 second) 指定运行时间为23:59:00 ON COMPLETION PRESERVE ENABLE 指定创建完成后即启用,否则需手动启动

Manually close events

ALTER EVENT e_delete_upvote DISABLE;

Manually this event is available

ALTER EVENT e_delete_upvote ENABLE;

View existing scheduled event tasks

SHOW EVENTS;

delete event

DROP EVENT e_delete_upvote;

Note: In a real development environment, the mysql service will be restarted or powered off. At this time, the event scheduler will be closed and all events will no longer work. To solve this problem, you need to use mysql Add the event_scheduler = ON; statement to the .ini file

Guess you like

Origin blog.csdn.net/qq_34591972/article/details/132168523