Monday, May 16, 2011

mysql event scheduler

Since Mysql 5.1.6, it supports a feature: event. Using this feature, we can make mysql run schedule tasks that we used to do in cron.

First, we activate the the event_scheduler

SET GLOBAL event_scheduler = 1;

Now, we can create an event

use test;

create table event_test (value datetime);

create event update_event on schedule every 1 second 
do
insert into event_test values(now());

Let 's wait for seconds and check the result:


select * from event_test;

+---------------------+
| value               |
+---------------------+
| 2011-05-17 11:56:14 |
| 2011-05-17 11:56:15 |
| 2011-05-17 11:56:16 |
| 2011-05-17 11:56:17 |
| 2011-05-17 11:56:18 |
| 2011-05-17 11:56:19 |
| 2011-05-17 11:56:20 |
+---------------------+

No comments: