1. 程式人生 > >mysql用法之建立事件

mysql用法之建立事件

1 建立事件:每天凌晨兩點自動刪除de_records表中七天以前的資料

CREATE EVENT event_delete_de_records_7days ON SCHEDULE EVERY 1 DAY STARTS '2018-01-01 02:00:00' DO DELETE FROM de_records WHERE timestamp <DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 7 DAY);


2. 建立事件:每天凌晨三點自動刪除as_records表中七天以前的資料

CREATE EVENT event_delete_as_records_7days ON SCHEDULE EVERY 1 DAY STARTS '2018-01-01 03:00:00' DO DELETE FROM as_records WHERE timestamp <DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 7 DAY);