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);

3、开启事件的用法

1、检测事件是否开启
show variables like 'event_scheduler';
2.开启事件
set global event_scheduler = on;
3、登录mysql中
show databases;
use mysql;
#查看事务
select name from event;
or
use chatroom;
show events;

#删除事务
语法:
drop event 表名
示例:
drop event 4332432143243

posted @ 2018-11-03 14:15  努力哥  阅读(6575)  评论(0编辑  收藏  举报