Mysql timer Open, invoke implementation code _MYSQL

Source: Internet
Author: User
To create a test table
Copy Code code as follows:

CREATE TABLE T
(
V VARCHAR (MB) not NULL
) ENGINE INNODB DEFAULT Charset=utf8;
Creating a stored procedure for a timer call
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 for the timer to function.
--See if the timer is turned on
Show VARIABLES like '%sche% ';
--Open Timer 0:off 1:on
SET GLOBAL event_scheduler = 1;
--Create 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 ();
--Open Event
ALTER EVENT event_test on
Completion PRESERVE ENABLE;
--Shutdown Event
ALTER EVENT event_test on
Completion PRESERVE DISABLE;
Run every nine days from now on
CREATE EVENT EVENT1
On SCHEDULE EVERY 9 Day starts now ()
On completion PRESERVE ENABLE
Todo
BEGIN
Call Total ();
End
Every month, one, 1 o'clock in the morning.
CREATE EVENT EVENT2
On SCHEDULE EVERY 1 MONTH starts Date_add (Date_add (Date_sub (), Curdate Day (INTERVAL ())-1 day), Curdate 1 INTERVAL), I Nterval 1 HOUR)
On completion PRESERVE ENABLE
Todo
BEGIN
Call STAT ();
End
Every quarter of the 2 o'clock in the morning execution
CREATE EVENT total_season_event
On SCHEDULE EVERY 1 quarter starts Date_add (Date_add (CONCAT (), '-', ELT (curdate (Quarter ()), curdate ), '-', 1), INTERVAL 1 quarter), INTERVAL 2 HOUR)
On completion PRESERVE ENABLE
Todo
BEGIN
Call Season_stat ();
End
January 1 every year four o'clock in the morning implementation
CREATE EVENT total_year_event
On SCHEDULE EVERY 1 starts date_add (DATE (CONCAT () + 1, '-', 1, '-', 1)), Curdate 4 INTERVAL)
On completion PRESERVE ENABLE
Todo
BEGIN
Call Year_stat ();
End

MySQL event in the monthly, quarterly, annual automatic call stored procedures, in order to test the system can be changed to the last day of the year, such as 2010-12-31 23:59:55;

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.