Archive for May, 2009

MySQL: Event scheduler is introduced in 5.1.6

Now MySQL allows executing tasks that run according to a schedule:

MySQL Events are tasks that run according to a schedule. Therefore, we sometimes refer to them as scheduled events. When you create an event, you are creating a named database object containing one or more SQL statements to be executed at one or more regular intervals, beginning and ending at a specific date and time. Conceptually, this is similar to the idea of the Unix crontab (also known as a “cron job”) or the Windows Task Scheduler.

Here is a sample SQL to create an event:

CREATE EVENT e_hourly
    ON SCHEDULE 
      EVERY 1 HOUR
    COMMENT 'Clears out sessions table each hour.'
    DO
      DELETE FROM site_activity.sessions;

Read more in MySQL reference manual: 19.4. Using the Event Scheduler as well as how this feature was originally designed by Andrey Hristov when he was working on his master’s thesis.

« Previous Page