Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Analysis of the method of setting timing Task by mysql

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Examples of this article describes the mysql implementation of the method of setting timing tasks. Share it for your reference, as follows:

Today, I encountered a task that needs to be performed regularly every day. I provided such a function in mysql database, which happened to be sorted out and shared.

1. First check if timed tasks are enabled

Check if the event is open:

SHOW VARIABLES LIKE '%event_sche%';

Turn event scheduling on:

SET GLOBAL event_scheduler = 1;

Close the event schedule:

SET GLOBAL event_scheduler = 0;

Close Event Task:

ALTER EVENT eventName ON COMPLETION PRESERVE DISABLE;

Open Event Quest:

ALTER EVENT eventName ON COMPLETION PRESERVE ENABLE;

View Event Tasks:

SHOW EVENTS ;

2. create a stored procedure

DELIMITER //DROP PROCEDURE IF EXISTS p_test//CREATE PROCEDURE p_test()BEGININSERT INTO test(name, create_time) values('testName', now());END//

3. Set the timer task to invoke this stored procedure (executed every ten seconds from 1:00 on August 8, 2015)

DROP EVENT IF EXISTS e_test//CREATE EVENT e_testON SCHEDULE EVERY 10 second STARTS TIMESTAMP '2015-08-08 01:00:00'ON COMPLETION PRESERVEDOBEGINCALL p_test();END//

Note: In event: ON SCHEDULE scheduled task, there are two ways to set scheduled task:

1. AT timestamp, used to complete a single scheduled task.

2. EVERY The number of time units [STARTS timestamps] [ENDS timestamps] used to complete repetitive scheduled tasks.

In both scheduled tasks, the timestamp can be any of the TIMESTAMP and DATETIME data types, and the timestamp needs to be greater than the current time.

In repetitive scheduled tasks, the quantity of time (unit) can be any integer expression that is not null. The unit of time is the keyword: YEAR, MONTH, DAY, HOUR, MINUTE, or SECOND.

Note: Other time units are legal, such as QUARTER, WEEK, YEAR_MONTH,DAY_HOUR,DAY_MINUTE,DAY_SECOND,HOUR_MINUTE,HOUR_SECOND, MINUTE_SECOND.

[ON COMPLETION [NOT] PRESERVE]

The ON COMPLETION parameter indicates "when this event will not occur again," i.e., when a single scheduled task has been executed or when repetitive scheduled tasks have reached the ENDS stage. PRESERVE is used to prevent the event from being dropped after execution. It is recommended to use this parameter to view the specific information of EVENT.

More about MySQL related content interested readers can view this site topic: MySQL query skills, MySQL transaction operation skills, MySQL storage process skills, MySQL database lock related skills, MySQL common function summary

I hope this article is helpful for MySQL database.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report