Usage of mysqlevent bitsCN.com
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. 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 -- 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: run the create event EVENT1 on schedule every 9 day starts now () on completion preserve enable do begin call total () EVERY nine days from now on (); 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 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 execute create event TOTAL_YEAR_EVENT on schedule every 1 year starts DATE_ADD (DATE (CONCAT (YEAR (CURDATE () at ON January 1, January 1 EVERY YEAR ()) + 1, '-', 1, '-', 1), INTERVAL 4 HOUR) on completion preserve enable do begin call YEAR_STAT (); END bitsCN.com
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.