Simple mysql scheduled task example _ MySQL

Source: Internet
Author: User
A simple example of a mysql scheduled task: bitsCN.com

A simple example of a mysql scheduled task

If you want to execute the following statement every 30 seconds: [SQL] update userinfo set endtime = now () WHERE id = '000000'; you can create a scheduled task for mysql as follows: [SQL] delimiter // * sets the statement terminator to //, because the stored procedure statement is used; end */

1. check whether the event is enabled.

[SQL] show variables like '% sche %'; enable event_scheduler [SQL] set global event_scheduler = 1;

II. create a stored procedure test

[SQL] CREATE PROCEDURE test () BEGIN update userinfo set endtime = now () where id = '2013'; END;

3. create event e_test

[SQL] 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 to close the event task [SQL] alter event e_test on completion preserve disable; the account opening event task [SQL] alter event e_test ON COMPLETION PRESERVE ENABLE;

BitsCN.com

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.