MySQL scheduled task example tutorial

MySQL scheduled task example tutorial

Preface

Since MySQL 5.1.6, a very unique feature has been added - Event Scheduler, which can be used to perform certain specific tasks (such as deleting records, aggregating data, etc.) at a scheduled time to replace the work that could only be performed by the operating system's scheduled tasks. What is more worth mentioning is that MySQL's event scheduler can execute a task accurately to every second, while the operating system's scheduled tasks (such as CRON under Linux or task scheduling under Windows) can only be executed accurately to once per minute. It is very suitable for applications that have high requirements for real-time data (such as stocks, odds, scores, etc.).

This article will give you a detailed introduction about MySQL scheduled tasks and share it for your reference. Let's take a look at the detailed introduction.

mysql scheduled tasks

Application scenario: Automatically change the order status to received 15 days after delivery

Implementation method: MySQL event

1. Check whether the event is enabled. It is disabled by default. SHOW VARIABLES LIKE 'event_scheduler';

2. Enable event set global event_scheduler=on;

3. Create a function

Note the following parameters

4. Then just start it in your own code. It is usually enabled when shipping in the background (I also include the function of automatically canceling orders within 15 minutes)

Attached to close the scheduled task

alter event event_day_update ON COMPLETION PRESERVE DISABLE;

Summarize

The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. If you have any questions, you can leave a message to communicate. Thank you for your support for 123WORDPRESS.COM.

You may also be interested in:
  • How to configure MySQL scheduled tasks (EVENT events) in detail
  • MySQL scheduled task implementation and usage examples
  • Analysis of the method of setting up scheduled tasks in mysql
  • Detailed explanation of mysql scheduled tasks (event events)
  • How to implement Mysql scheduled task backup data under Linux
  • How to implement Mysql scheduled tasks under Linux
  • Analysis and solution of the reasons why MySQL scheduled tasks cannot be executed normally

<<:  Coexistence of python2 and python3 under centos7 system

>>:  JavaScript timer to achieve seamless scrolling of pictures

Recommend

Detailed explanation of MySQL precompilation function

This article shares the MySQL precompilation func...

jQuery implements clicking left and right buttons to switch pictures

This article example shares the specific code of ...

Specific use of MySQL global locks and table-level locks

Table of contents Preface Global Lock Table lock ...

MySQL Billions of Data Import, Export and Migration Notes

I have been taking a lot of MySQL notes recently,...

mysql 5.6.23 winx64.zip installation detailed tutorial

For detailed documentation on installing the comp...

A brief discussion on the principle of js QR code scanning login

Table of contents The essence of QR code login Un...

Detailed explanation of how Nginx works

How Nginx works Nginx consists of a core and modu...

CSS to achieve the effect of rotating flip card animation

The css animation of the rotating flip effect, th...

How to install MySQL 5.7.17 and set the encoding to utf8 in Windows

download MySQL official download, select Windows ...

This article helps you understand PReact10.5.13 source code

Table of contents render.js part create-context.j...

MySQL 8.0.17 installation and configuration method graphic tutorial

This article shares the installation and configur...

JavaScript to achieve a simple carousel effect

What is a carousel? Carousel: In a module or wind...