MySQL Event Scheduler

Source: Internet
Author: User

The event scheduler in MySQL is a new feature after MySQL 5.1. The database can be made, added, deleted, modified and manipulated in accordance with the specified time period. Equivalent to the unmanned scheduler in Linux crontab ( For the operation of the related crontab, see my Linux planning tasks. Avoid some data related timing tasks in the business operations layer, reduce the risk of operator misoperation, greatly shorten the workload to improve efficiency.

The following syntax is introduced first:

CREATE EVENT [IF not EXISTS] Event_Name

On SCHEDULE SCHEDULE

[on completion [NOT] PRESERVE]

[ENABLE | DISABLE]

[COMMENT ' COMMENT ']

Do sql_statement

Schedule

at TIMESTAMP [+ INTERVAL INTERVAL]

| Every INTERVAL [starts TIMESTAMP] [ENDS TIMESTAMP]

INTERVAL:

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

WEEK | SECOND | Year_month | Day_hour | Day_minute |

Day_second | Hour_minute | Hour_second | Minute_second}

Description: An optional item in brackets to specify how often the task executes. Specify the specific action to be performed by the DO clause.

Create a scheduled task each three seconds you want to insert a test data into a table. Examples are as follows:

(1) Create test table both:(note: Just in order to simulate the database password forgot to do the following database to stop operation, when you start to pay attention must be the process of mysqldkill off otherwise unable to start.)

Next create the test library, this example uses the table previously used for testing: t_time, create the following statement:

  

CREATE TABLE ' T_time ' (
' d ' date is DEFAULT NULL,
' t ' time DEFAULT NULL,
' DT ' datetime DEFAULT NULL,
' UpdateTime ' timestamp not NULL DEFAULT current_timestamp COMMENT ' last update
Room

) Engine=innodb DEFAULT Charset=utf8;

(2) Create Event Scheduler Event_insert_t_time

(3) To see if the event Scheduler was created successfully: A description was created successfully.

(4) After a few seconds there is no data in the view table.

(5) Check the status of the scheduler to see if it is turned on, (default is OFF)

(6) Open Scheduler

(7) View the data in the table

(8) Design Scheduler disabled

(9) If not, you can delete the Scheduler command as follows:

Drop event event_insert_t_time;

This article I original, welcome reprint reprint Please explain the source.

MySQL Event Scheduler

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.