当前位置:网站首页>MySQL定时调用预置函数完成数据更新
MySQL定时调用预置函数完成数据更新
2022-07-29 04:50:00 【追寻上飞】
MySQL定时调用预置函数完成数据更新
一、软件准备
- Navicat
- MySQL5.7

二、开启MySQL事件计划
查询MySQL事件计划是否开启。
show VARIABLES LIKE 'event%';

如果未开启就打开。
SET GLOBAL event_scheduler = 1;
三、创建MySQL函数
函数和过程十分类似,因此就直接创建函数,Navicat软件也把过程和函数统一放在函数菜单栏。
3.1 写SQL语句
编写需求业务的SQL语句,并进行测试,如将某个终端的数据整体后移3个月。
update table set date = DATE_ADD(date,INTERVAL 3 month) WHERE number = '110'
3.2 创建函数
BEGIN
#Routine body goes here...
update table set date = DATE_ADD(date,INTERVAL 3 month) WHERE number = '110';
RETURN 0;
END;

点击保存,给函数命名为 updateData,参数设置为空,完成函数的创建。

在函数菜单栏能看到刚才保存的函数。
3.3 创建事件
call updateData
状态设置为 ENABLE。
ON COMPLETETION设置为 PERSERVE,该参数表示"当这个事件不会再发生的时候",即当单次计划任务执行完毕后或当重复性的计划任务执行到了ENDS阶段。而PRESERVE的作用是使事件在执行完毕后不会被杀掉。

同样的,给事件命名,事件菜单栏会出现刚保存的事件。
接着给对事件的调用周期进行设置。

四、查询事件计划
SELECT * from mysql.`event`;
出现以下事件计划的详细信息,

边栏推荐
- Install the gym corresponding to mujoco in the spinning up tutorial, and the error mjpro150 is reported
- Leetcode 686. KMP method of repeatedly superimposing strings (implemented in C language)
- What are the core features of the digital transformation of state-owned construction enterprises?
- Traffic flow prediction pit climbing record (I): traffic flow data set, original data
- On the use of pyscript (realizing office preview)
- Software test interview questions (4)
- Understand the Internet giant [the war between China and Taiwan] and the development thinking of China and Taiwan
- 1 sentence of code, get asp Net core binds multiple sources to the same class
- VScode配置makefile编译
- Recommendation system of online education
猜你喜欢

1 句代码,搞定 ASP.NET Core 绑定多个源到同一个类

Unity Foundation (3) -- various coordinate systems in unity

IOS interview preparation - Online

让你的正则表达式可读性提高一百倍

Flink+Iceberg环境搭建及生产问题处理

Climbing the pit of traffic flow prediction (II): the simplest LSTM predicts traffic flow using tensorflow2

Install the gym corresponding to mujoco in the spinning up tutorial, and the error mjpro150 is reported

The most complete NLP Chinese and English stop words list in the whole station (including punctuation marks, which can be copied directly)

2022杭电多校联赛第四场 题解

带你一文理解JS数组
随机推荐
Leetcode 686. KMP method of repeatedly superimposing strings (implemented in C language)
EF Core: 一对一,多对多的配置
在线教育的推荐系统
Review key points and data sorting of information metrology in the second semester of 2022 (teacher zhaorongying of Wuhan University)
Christmas tree web page and Christmas tree application
Mysql:The user specified as a definer (‘root‘@‘%‘) does not exist 的解决办法
EMI interference troubleshooting with near-field probe and current probe
spinning up安装完使用教程测试是否成功,出现Library“GLU“ not found和‘from pyglet.gl import *错误解决办法
Idea small settings
数据湖:分布式开源处理引擎Spark
Mysql:the user specified as a definer ('root '@'%) does not exist
使用更灵活、更方便的罗氏线圈
Makefile+make Basics
IOS interview preparation - Objective-C
Hengxing Ketong invites you to the 24th China expressway informatization conference and technical product exhibition in Hunan
OpenCV环境搭建
正确的用户拖拽方式
Flink+Iceberg环境搭建及生产问题处理
The most complete NLP Chinese and English stop words list in the whole station (including punctuation marks, which can be copied directly)
Auto.js脚本开发入门