Simple Example of EVENT Scheduler In MySQL

THe Mysql has great flexibility in database.It has triggers,stored procedure and much more.When you want run a SQL based on change of table data(like event occurred on data), then you need to create Trigger.
But MySQL also has magic EVENT Scheduler functionality, its like cron job which will RUN on specific time.EX:
You need to delete all data of table on specific time,In script level you can create cron job which will RUN on schedule time.
BUT in database level you can create EVENT on database which will RUN on schedule time.

How to check EVEN Scheduler is enabled
Run below command on mysql for check setting of event scheduler:
[code type=mysql]
SHOW PROCESSLIST

If you will get below row that’s mean your Mysql has enable:
event_schedular_status

The Syntax to Create Event Schedular in MySql

This statement creates and schedules a new event. The event will not run unless the Event Scheduler is enabled.
you can get more details from MySQL CREATE EVENT Syntax documentation

The schedule can be assigned various settings, e.g.

Run Event Scheduler once on a specific date/time

Run Event Scheduler once after a specific period has elapsed

Run Mysql Event Scheduler at specific intervals forever

Run Event Scheduler at specific intervals during a specific period

You can also dropped once its schedule has expired with help of (ON COMPLETION NOT PRESERVE).
IF you will set (ON COMPLETION PRESERVE) then your event will preserve after schedule.

How to Create Scheduled Events in MySQL

Note: Above EVENT run every 1 min.