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

Mysql's scheduled task example tutorial

2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

Preface

Since MySQL5.1.6, a very unique feature has been added-event Scheduler (Event Scheduler), which can be used to perform certain tasks on a regular basis (such as deleting records, summarizing data, and so on) to replace work that can only be performed by scheduled tasks of the operating system. What is more worth mentioning is that MySQL's event scheduler can be accurate to execute one task per second, while the operating system's scheduled tasks (such as CRON under Linux or task scheduling under Windows) can only be executed exactly once per minute. It is very suitable for some applications that require high real-time data (such as stocks, odds, scores, etc.).

This article will give you a detailed introduction to the relevant contents of mysql timing tasks, and share them for your reference and study. I won't say much below. Let's take a look at the detailed introduction.

Mysql scheduled task

Application scenario: automatically change the order status to received 15 days after shipment

Implementation method: event event of mysql

1. Check whether the event event is enabled. The default is SHOW VARIABLES LIKE 'event_scheduler'.

two。 Enable event event set global event_scheduler=on

3. Create function

Pay attention to the input parameters.

4. Next, you can start it in your own code, which is usually enabled when you ship in the background (I also include a 15-minute automatic order cancellation feature here)

Closed scheduled task is attached

Alter event event_day_update ON COMPLETION PRESERVE DISABLE

Summary

The above is the whole content of this article, I hope that the content of this article has a certain reference and learning value for your study or work, if you have any questions, you can leave a message and exchange, thank you for your support.

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