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

Steps to install superset under win10 system

Superset is a lightweight self-service BI framewo...

Detailed explanation of several ways to create objects and object methods in js

This article is the second article about objects ...

JavaScript to achieve click image flip effect

I was recently working on a project about face co...

Windows DNS server exposed "worm-level" vulnerability, has existed for 17 years

Vulnerability Introduction The SigRed vulnerabili...

In-depth understanding of CSS @font-face performance optimization

This article mainly introduces common strategies ...

Solution to Django's inability to access static resources with uwsgi+nginx proxy

When deploying uwsgi+nginx proxy Django, access u...

An article to understand operators in ECMAScript

Table of contents Unary Operators Boolean Operato...

How to configure Openbox for Linux desktop (recommended)

This article is part of a special series on the 2...

Introduction to JavaScript strict mode use strict

Table of contents 1. Overview 1.1 What is strict ...

How to install mysql via yum on centos7

1. Check whether MySQL is installed yum list inst...

MySQL 8.0.11 installation summary tutorial diagram

Installation environment: CAT /etc/os-release Vie...

An article teaches you how to implement a recipe system with React

Table of contents 1. Recipe Collection 1.1 Projec...

CSS3 flexible box flex to achieve three-column layout

As the title says: The height is known, the width...