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

How to implement timing execution in mysql

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

How to implement timing execution in mysql? in view of this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.

After version 5.1, MYSQL supports timing execution (event), which is similar to linux's crontab.

First take a look at your MSYQL version and query the SQL statement for version information:

Select VERSION ()

After confirming the version support, check whether event is enabled:

Show variables like'% sche%'

If it is not open, how can it be opened?

Show VARIABLES LIKE'% sche%'

Set global event_scheduler = 1

Show VARIABLES LIKE'% sche%'

In general, there are two kinds of timing execution:

1. From a specific point in time, it will be executed at regular intervals.

From now on, it will be 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 (2pr 3)

2. Start from a specific point in time and execute at a certain point in the day.

Executed at 1: 00 a. M. on the first of every month

Create event if not exists e_test2

On schedule every 1 month starts DATE_ADD (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 (2pr 3)

You can also turn off the event task:

Alter event e_test ON

COMPLETION PRESERVE DISABLE

Open event tasks that have been closed:

Alter event e_test ON

COMPLETION PRESERVE ENABLE

This is the answer to the question about how to implement timing execution in mysql. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel to learn more about it.

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