1.查看event_scheualer的状态
show variables like 'event_scheduler';
2.设置开启状态
set global event_scheduler = on 或 1;
2.设置关闭状态
set global event_scheduler = off 或 0;
mysql5.1版本开始引进event概念。event既“时间触发器”,与triggers的事件触发不同,event类似与linux crontab计划任务,用于时间触发。通过单独或调用存储过程使用,在某一特定的时间点,触发相关的SQL语句或存储过程。
创建格式:
create event [if not exists] event_nameon schedule myschedule[on completion [not] preserve][enable | disable][comment 'comment']do sql_statement; 上面myschedule的格式为at timestamp [+ interval myinterval] | every myinterval [starts timestamp] [ends timestamp]上面myinterval的格式为数量 {year | quarter | month | day | hour | minute | week | second | year_month | day_hour | day_minute | day_second | hour_minute | hour_second | minute_second}
每天清空数据表:
delimiter $$create EVENT `test`.`event_demo3`on schedule every 1 daydo begin truncate table t_schedule; end$$delimiter ;
推荐看下这篇