mysql-Scheduled Tasks

Source: Internet
Author: User

MySQL timed tasks are introduced from version 5.1, also known as temporary triggers, but unlike normal triggers, a normal trigger is an event triggered by manipulating every row of data in a data table, and it is triggered by a point in time or time period

First look at its syntax:

DELIMITER $$--SET GLOBAL Event_scheduler = on$$--Required for event to execute and not createCREATE    /*[definer = {User | Current_User}]*/EVENT ' event1 ' onSCHEDULE/*Uncomment the example below you want*/    --scheduleexample 1:run once       --At ' Yyyy-mm-dd hh:mm. SS '/current_timestamp {+ INTERVAL 1 [hour| month| week| day| Minute| ...] }    --scheduleexample 2:run at intervals forever after creation       --every 1 [hour| month| week| day| Minute| ...]    --scheduleexample 3:specified start time, end time and interval for execution       /*every 1 [hour| month| week| day|       Minute| ...] Starts current_timestamp/' Yyyy-mm-dd hh:mm. SS ' {+ INTERVAL 1[hour| month| week| day| Minute| ...] } ENDS current_timestamp/' Yyyy-mm-dd hh:mm. SS ' {+ INTERVAL 1 [hour| month| week| day| Minute| ...] } *//*[on completion [NOT] preserve][enable | Disable][comment ' COMMENT ']*/ DoBEGIN(sql_statements)END$ $DELIMITER;

Basically through the above syntax to understand how to use, the following for each way can write a little chestnut

1, Trigger (execute once) at a certain point in time:

DELIMITER $$CREATEEVENT ' bdhp '. ' E_e1 ' onSCHEDULE/*Execute only once*/        /*At ' 2015-02-03 16:07.00 '*//*a certain point in time*/           /*At ' 2015-02-03 16:47.20 ' + INTERVAL second*//*A point in time + a period of time*/ atCurrent_timestamp+INTERVAL +SECOND/*current point in time + period of time*/ DoBEGIN        INSERT  intoT_sys_log (SN)VALUES('55555'); END$ $DELIMITER;

2, per cycle, infinite number of times

DELIMITER $$ CREATE      EVENT ' e_e2 'on  SCHEDULE           1  minutedo    BEGIN        INSERT into T_sys_log (SN)VALUES('55555' );     END $ $DELIMITER;

3, in a certain time period, by the cycle execution (ends does not write is to start from a point of execution)

DELIMITER $$CREATEEVENT ' e_e3 ' onSCHEDULE every1SECOND startsCurrent_timestampENDS'2015-02-03 16:15.00' DoBEGIN        INSERT  intoT_sys_log (SN,user_name)VALUES('Test','ttt-55'); END$ $DELIMITER;

mysql-Scheduled Tasks

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.