1.创建一个测试表
CREATE TABLE aaa (timeline TIMESTAMP);
2.创建一个事件:每秒插入一条记录到数据表
CREATE EVENT e_test_insert ON SCHEDULE EVERY 1 SECOND DO INSERT INTO aaa VALUES (CURRENT_TIMESTAMP);
3.每天定时清空aaa表:
-- 每天定时情况aaa表 CREATE EVENT e_test on schedule every 1 DAY starts timestamp ‘2016-12-19 12:00:00‘ do truncate table aaa;
4.每天定时情况aaa表,5天后停止执行
-- 每天定时情况aaa表,5天后停止执行 drop event if exists e_test; create event e_test on schedule every 1 day ends current_timestamp + INTERVAL 5 day do truncate table aaa;
5.5天后开启每天定时清空test表,一个月后停止执行
-- 5天后开启每天定时清空test表,一个月后停止执行 CREATE EVENT e_test ON SCHEDULE EVERY 1 DAY STARTS CURRENT_TIMESTAMP + INTERVAL 5 DAY ENDS CURRENT_TIMESTAMP + INTERVAL 1 MONTH DO TRUNCATE TABLE aaa;
时间: 2024-10-12 08:29:38