Events in MySQL (Scheduled tasks)

Source: Internet
Author: User

I. What is an event

A set of SQL sets, used to perform timed tasks, much like a trigger, is executed passively, because time is triggered and the trigger is triggered by an event (incremental deletion).

Second, the opening event

To see if it is turned on:

 like ' Event_scheduler ';

If off is displayed, enter the following statement to open:

Set = off;
Iii. Custom Simple Events

To create a new user table:

-- ------------------------------Table structure for ' user '-- ----------------------------DROP TABLE IF EXISTS`User`;CREATE TABLE`User' (' ID 'bigint( -) not NULLauto_increment, ' name 'varchar( $) not NULL, ' address 'varchar( -) not NULL, ' Addtime 'datetime  not NULL,  PRIMARY KEY(' id ')) ENGINE=InnoDBDEFAULTCHARSET=UTF8;

Create a new time and insert a single piece of data every minute:

Parameter description:

Definer: creator;

On completion [NOT] PRESERVE: indicates that when the time does not occur, delete the event (note the event at a specific time, if the parameter is set, the event will be deleted when the execution is complete, and you can set it to on if you do not want to delete it). Completion PRESERVE);

ENABLE: indicates that the system will execute this event;

-- ------------------------------Event structure for ' Event_minute '-- ----------------------------DROPEVENTIF EXISTS' Event_minute ';D elimiter;;CREATEDefiner=' Root ' @ ' localhost ' EVENT ' event_minute ' onSCHEDULE every1MINUTE starts'2016-01-17 14:49:43'  onCompletion notPRESERVE ENABLE Do

BEGIN INSERT into USER(Name, Address,addtime)VALUES('test1','test1', now ()); INSERT into USER(Name, Address,addtime)VALUES('test2','test2', now ());END;;D Elimiter;

Create a new event, specific time 2016-01-17 15:30:00 insert a piece of data

-- ------------------------------Event structure for ' event_at '-- ----------------------------DROPEVENTIF EXISTS' event_at ';D elimiter;;CREATEDefiner=' Root ' @ ' localhost ' EVENT ' event_at ' onSCHEDULE at'2016-01-17 15:30:00'  onCompletion notPRESERVE ENABLE Do

BEGIN INSERT into USER(Name, Address,addtime)VALUES(' at',' at', now ());END;;D Elimiter;

To view the results, the results are correct:

Events in MySQL (Scheduled tasks)

Related Article

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.