MySQL timed execution script (scheduled Task) instance

Source: Internet
Author: User

See if the event is open

The code is as follows Copy Code
Show variables like '%sche% ';

To open an event plan

The code is as follows Copy Code
Set global Event_scheduler = 1;

Create stored Procedure test

The code is as follows Copy Code
CREATE PROCEDURE Test ()
BEGIN
Update Examinfo SET endtime = Now () WHERE id = 14;
End;

Create Event E_test

The code is as follows Copy Code
Create event if not exists e_test
On schedule every second
On completion Preserve
Do call Test ();

The stored procedure test is executed every 30 seconds, and the current time is updated to the Endtime field of the id=14 record in the Examinfo table.

Shutdown Event Task

The code is as follows Copy Code
Alter event e_test on
Completion PRESERVE DISABLE;

Account Opening Event Task

The code is as follows Copy Code
Alter event e_test on
Completion PRESERVE ENABLE;

All of the above tests were successful and the test environment was MySQL 5.4.2-beta-community MySQL Community server (GPL)

The above related content is the introduction of the MySQL timing, hope you can have some harvest.

MySQL scheduled task restarts and disappears


We just need to modify a configuration to

Event_scheduler is set to off in MySQL config. Go to MySQL and change the configuration to on and it's done.

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.