How to regularly execute mysql

Source: Internet
Author: User

MYSQL 5.1 and later versions support the scheduled execution (event) function, which is similar to linux crontab.
 
First, check your MSYQL version and the SQL statement for querying version information:
 
Select VERSION ()
After confirming the version support, check whether the event is Enabled:
 
Show variables like '% sche % ';
If not, how can I enable it?
 
Show variables like '% sche % ';
Set global event_scheduler = 1;
Show variables like '% sche % ';
Generally, there are two types of scheduled execution:
 
1. Execute the task at intervals starting from a specific time point;
 
From now on, it is executed every 30 seconds.
 
Create event if not exists e_test
On schedule every 30 second starts now ()
On completion preserve
Do
INSERT into sdb_yoyi (yoyiscid, orderid) VALUES (2, 3)
2. Execute the task from a specific time point on the current day;
 
Execute the task at on the first day of each month.
 
Create event if not exists e_test2
 
On schedule every 1 month starts DATE_ADD (DATE_SUB (CURDATE (), interval day (CURDATE ()-1 DAY), INTERVAL 1 MONTH), INTERVAL 1 HOUR)
 
On completion preserve
 
Do
 
INSERT into sdb_yoyi (yoyiscid, orderid) VALUES (2, 3)
 
 
 
You can also close the event task:
 
Alter event e_test ON
 
Completion preserve disable;
 
Enable closed event tasks:
 
Alter event e_test ON
 
Completion preserve enable;

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.