Mysql event usage MySQL supports the event function from 5.1, similar to the job function of oracle. With this function, we can enable MySQL to automatically execute data aggregation and other functions without the need for timer support provided by the operating system. For example, the linux crontab function. Www.2cto.com CREATE test table create table t (v VARCHAR (100) not null) engine innodb default charset = utf8; DELIMITER $ drop procedure if exists e_test $ create procedure e_test () begin insert into t VALUES ('1'); END $ DELIMITER; the constant GLOBAL event_scheduler of MySQL must be on or 1 www.2cto.com -- check whether the timer show variables like '% sche %' is enabled; -- enable the timer 0: off 1: on set global event_scheduler = 1; -- creates an EVENT -- automatically calls the e_test () stored procedure every second. create event if not exists event_test on schedule every 1 second on completion preserve do call e_test (); -- enable event alter event event_test on completion preserve enable; -- disable event alter event event_test on completion preserve disable; SELECT * FROM t; some examples: from now on, run the create event EVENT1 on schedule every 9 day starts now () on completion preserve enable do begin call total () EVERY nine days (); END: Execute create event EVENT2 on schedule every 1 month starts DATE_ADD (DATE_SUB (CURDATE (), interval day (CURDATE ()-1 DAY) ), INTERVAL 1 MONTH), INTERVAL 1 HOUR) on completion preserve enable do begin call stat (); END www.2cto.com execute create event TOTAL_SEASON_EVENT on schedule every 1 quarter starts DATE_ADD (DATE (CONCAT (YEAR (CURDATE ()),'-', ELT (QUARTER (CURDATE (),), '-', 1), INTERVAL 1 QUARTER), INTERVAL 2 HOUR) on completion preserve enable do begin call SEASON_STAT (); END executes www.2cto.com create event TOTAL_YEAR_EVENT on schedule every 1 year starts DATE_ADD (DATE (CONCAT (YEAR (CURDATE () at ON January 1 ()) + 1, '-', 1, '-', 1), INTERVAL 4 HOUR) on completion preserve enable do begin call YEAR_STAT (); END