[DB]-MySQL Create timed task

Source: Internet
Author: User
Tags mysql create

MySQL supports the creation of timed tasks, requiring the MySQL server to start scheduled task scheduling.

1. Check if scheduled task execution is turned on
SHOW VARIABLES like ' Event_scheduler '; Off means no open
2. Turn on timed tasks
SET GLOBAL event_scheduler = on;
Or
Add Event_scheduler = 1 in the my.cnf file

3. Writing timed Tasks

Syntax rules:

CREATE EVENT [IF not EXISTS] Event_Name//Specify name

On SCHEDULE SCHEDULE//Specify task scheduling rules

On completion [NOT] PRESERVE//Specifies whether the task is executed one time, or multiple times, not given when not, is executed one time, and executes multiple times by default

[disable| Enable]//Specify whether the task is active, activate by default enable

[COMMENT ' COMMENT ']//specify annotations, comments

Do sqlstament//Specify the specific execution SQL

Schedule rules:

at TIMESTAMP [+ INTERVAL INTERVAL] | Every INTERVAL [starts TIMESTAMP] [ENDS TIMESTAMP]

Interval rules:

Quantity {Year | QUARTER | MONTH | Day | HOUR | MINUTE | WEEK | SECOND | Year_month | Day_hour | Day_minute | Day_second | Hour_minute | Hour_second | Minute_second}

Quantity to Digital

4. Case studies

Use test;
CREATE TABLE ' e_t ' (
' Timeline ' timestamp not NULL DEFAULT current_timestamp on UPDATE current_timestamp
) Engine=myisam DEFAULT Charset=utf8;
CREATE EVENT Event_insert_et on SCHEDULE every 1 SECOND does insert into test.e_t VALUES (current_timestamp);

    

[DB]-MySQL Create timed task

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.