MySQL 5.1推出新特性——Event Scheduler,可以定时执行一些任务,给开发带来极大的便利。如果要使用Event Scheduler,首先检查是否启用了Event scheduler,如下:
mysql> select @@event_scheduler;
mysql> show variables like 'event_scheduler';
如果没有开启,开启它。
mysql> set GLOBAL event_scheduler=ON;
或
mysql> set GLOBAL event_scheduler=1;
我们先创建一个表
mysql> delimiter //
mysql> create table t_event (event_id int not null auto_increment primary key, created timestamp);
//
创建event
mysql> create event e_insert on schedule every 5 second starts timestamp '2010-01-12 23:22:00' enable do
insert into t_event (created) values(current_timestamp);
//
失效
mysql> alter event e_insert disable;