MySQL scheduled execution script (scheduled task) instance

Source: Internet
Author: User
Run the following code to check whether the event is Enabled: showvariableslike % sche %; run the following code to enable the event plan: setglobalevent_scheduler1; run the following code to create the stored procedure test: CREATEPROCEDUREtest () procedure () WHEREid14; END

Check whether the code for enabling the event is as follows: show variables like '% sche %'; set global event_scheduler = 1 as follows: create procedure test () BEGIN update examinfo SET endtime = now () WHERE id = 14; END; Create event e_te

Check whether event is enabled

The Code is as follows:

Show variables like '% sche % ';

Enable the event plan

The Code is as follows:

Set global event_scheduler = 1;

Create a stored procedure test

The Code is as follows:

Create procedure test ()

BEGIN

Update examinfo SET endtime = now () WHERE id = 14;

END;

Create event e_test

The Code is as follows:

Create event if not exists e_test

On schedule every 30 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 Record id = 14 in examinfo.

Close event task

The Code is as follows:

Alter event e_test ON

Completion preserve disable;

Account Opening event task

The Code is as follows:

Alter event e_test ON

Completion preserve enable;

All tests are successful. The test environment is mysql 5.4.2-beta-community mysql community server (GPL)

The above content is an introduction to the regular execution of MySQL. I hope you will have some gains.

The scheduled mysql task disappears after being restarted.

You only need to modify the configuration.

Event_scheduler is set to OFF in mysql config. Change the configuration to ON 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.