Event scheduling features in MySQL

Source: Internet
Author: User

There are several prerequisites for using the MySQL event feature:

One: The version used must be 5.1 or above, because 5.1 support this feature later

Second: Check if the event function is turned on:

SHOW VARIABLES like ' Event_scheduler ';

Show Off is off (the system is off by default)

The Open command is:

SET GLOBAL event_scheduler = 1;

Or

SET GLOBAL event_scheduler = on;

The commands to turn off the event feature are:

SET GLOBAL event_scheduler = 0;

Or

SET GLOBAL event_scheduler = OFF;

A few simple examples are implemented below

Example one: Inserting a record into the Eventtest1 table per second

CREATE EVENT event1 on SCHEDULE every 1SECOND does INSERT into Eventtest1 VALUES (Null,current_timestamp);

SELECT * from Eventtest1;

Temporary shutdown events

ALTER EVENT event1 DISABLE;

Turn on events

ALTER EVENT event1 ENABLE;

Modify event is not 5s executed once

ALTER EVENT event1 on SCHEDULE every 5SECOND;

Delete Event

DROP EVENT event6;

example Two: emptying the eventtest1 table regularly every day

CREATE EVENT Event2

On SCHEDULE every 1 day

Do TRUNCATE TABLE eventtest1;

example three:2014-12-31 23:59:59 empty eventtest1 table

CREATE EVENT Event3

On SCHEDULE at TIMESTAMP ' 2014-12-3123:59:59 '

Do TRUNCATE TABLE eventtest1;

example four:days after the beginning of the daily emptying eventtest1 table

CREATE EVENT Event4

On SCHEDULE every 1 day

Starts Current_timestamp + INTERVAL Day

Do TRUNCATE TABLE eventtest1;

example five: Empty the eventtest1 tableevery day and stop execution after 2 months

CREATE EVENT EVENT5

On SCHEDULE every 1 day

ENDS Current_timestamp + INTERVAL 2 MONTH

Do TRUNCATE TABLE eventtest1;

Example Six:5 days after the beginning of the daily emptying of the Eventtest1 table,3 months after the execution stop

CREATE EVENT Event6

On SCHEDULE every 1 day

Starts Current_timestamp + INTERVAL 5 Day

ENDS Current_timestamp + INTERVAL 3 MONTH

Do TRUNCATE TABLE eventtest1;

Note: After this test is done, the next time you do it, if you set up a table and events can be successful, but the table will not increase, must

To see if the next event function is turned on, the event function will automatically turn off if the shutdown or other reason


This article is from the "Keke" blog, make sure to keep this source http://keke51cto.blog.51cto.com/6467511/1547238

Event scheduling features in MySQL

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.