EVENTS / SCHEDULERS in MySQL

By Prasad Khode

MySQL event is a process that is performed  affecting the data on occurrence of certain specified conditions or at a scheduled time. Events are not like triggers which run in response to a change in data . Events  are scheduled to run any number of times like the cron  job is run.

MySQL Events have been added from version 5.1.6 MySQL. Event scheduler is a process that runs in background and looks for events to execute. Before we create or schedule an event in MySQL, we need to first verify whether i event-scheduler is enabled, by default it is OFF in MySQL.

To check whether scheduler is enabled or not, use the following command:

Issue the following command to turn on the scheduler.

To disable the scheduler run:

Use the following command to list all the events that are created.

Using events, we will insert records into some table; let us call it as test_table, on every day at a specific time. Our test_table will look as below:

The following will be used for creating an event which will insert a record into test_table for every 1 minute.

Once we have created our first_event, it will insert a new record every minute into test_table. If we want to alter the existing event to run hourly, once in an hour then

The following can be used drop the events from the database:

Reference:

https://dev.mysql.com/doc/refman/5.1/en/events-overview.html