Monday, November 4, 2013

Mysql Event Scheduler an alternative to cronjob.

Mysql introduce Event scheduler which we can use alternative to Cronjob. There are many advantages over cronjob like:
1) It is directly written on Mysql Server.
2) This is platform independent. Your application might be written in any language it does not matters. You just need to know mysql.
3) We can use them whenever there is a database update or cleanup required at regulare interval.
4) No need to compile queries every time hence performace increased.
5) Error can be log in log files.

Syntax:

DELIMITER //
CREATE EVENT eventName
ON SCHEDULE EVERY 1 WEEK
STARTS 'Some Date to start'
ENDS 'End date If any' 
DO
BEGIN
   // Your query will be here
END//
DELIMITER ;