MySQL Create Event Scheduler

Source: Internet
Author: User
Tags mysql create

The event scheduler in MySQL, which can be used to perform timed tasks.

First, open

Event scheduling is turned off by default, and executable is turned on.

To see if the event Scheduler is turned on:

SHOW VARIABLES like ' Event_scheduler '; SELECT @ @event_scheduler;

Turn on Event Scheduler

SET GLOBAL event_scheduler=1;

SET GLOBAL Event_scheduler=on;


Or add event_scheduler=1 to the My.ini file.

or add "-event_scheduler=1" after starting the command

To view an existing event scheduler

Show events;

To view the status of the event scheduler

Show Processlist;

Second, create the event scheduler

CREATE EVENT [IF not EXISTS] event_name on SCHEDULE SCHEDULE [on completion [NOT] PRESERVE] [ENABLE | DISABLE] [COMMENT ' COMMENT '] do sql_statement;

Schedule: Is the execution plan, there are two options, the first is to execute at a certain time, and the second is to be executed at intervals from one time to the next.

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

at TIMESTAMP [+ INTERVAL INTERVAL]: executed only at specified point in time;

Every INTERVAL [starts TIMESTAMP] [ENDS TIMESTAMP]: How long is the interval performed;

INTERVAL: Time interval, can be accurate to seconds.

Quantity {Year | QUARTER | MONTH | Day | HOUR | MINUTE |

WEEK | SECOND | Year_month

Event_Name: Is the event name you want to create

On completion [NOT] PRESERVE: Save after end, not save by default, once executed, the event is deleted, so it is strongly recommended that this parameter be set to on completion PRESERVE.

Do sql_statement: Can be a DML statement, a DCL statement, or a call to a stored procedure.

Third, modify the event scheduler

ALTER EVENT event_name [on SCHEDULE SCHEDULE] [RENAME to New_event_name] [on completion [NOT] PRESERVE] [COMME NT ' comment ' [ENABLE | DISABLE] [do sql_statement]

Iv. Example of Event Scheduler

Example 1: Adding data after 1 minutes

Create event if not exists eve_test on SCHEDULE @ current_timestamp () + interval 1 minute on completion PRESERVE Do insert to test_20161107 (T_day) VALUES (now ());

Example 2: Change to add data every 1 minutes

Alter event eve_test on schedule Every 1 minute starts now () on completion preserve enable doing insert into test _20161107 (T_day) VALUES (now ());

Use Show events to view the status of the event scheduler after modification;

Example 3: Calling a stored procedure

Alter event eve_test on schedule Every 1 minute starts today () On completion preserve enable does call Proc_test () ;

V. Delete

DROP EVENT [IF EXISTS] event_name;


This article is from the "three countries Cold jokes" blog, please be sure to keep this source http://myhwj.blog.51cto.com/9763975/1870202

MySQL Create Event Scheduler

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.