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);
3、开启事件的用法
1、检测事件是否开启
show variables like 'event_scheduler';2.开启事件set global event_scheduler = on;3、登录mysql中show databases;use mysql;#查看事务select name from event;oruse chatroom;show events;#删除事务
语法:drop event 表名示例:drop event 4332432143243