当前位置:网站首页>MySQL event_single event_timed loop event
MySQL event_single event_timed loop event
2022-08-09 09:11:00 【Hu Letian】
事件简介
MySQL自5.1Version introduction event,i.e. in fixed events,Do one fixed thing,And you can also decide that this thing is only executed once,It is also executed in a loop at a fixed interval.Along with the database visualization software more and more,There are many ways to create events,在这里,The two most commonly used are introduced,第一种,代码方式,第二种,使用NavicatCreated visually.
代码方式
-- 查看定时器是否开启,OFF为关
show variables like 'event_scheduler'
-- 开启定时任务,After this way is turned on,Database restart will automatically close
set global event_scheduler=1
-- 创建定时任务
create event lock_rpt
on schedule every 10 second
do
update rpt_template set report_status=1 where rpt_template_id in ('000','1B87483969B9431090F925E789F7C41A')
-- 定时任务格式
create event 事件名称
on schedule every 间隔时间
do
具体执行的SQL任务语句
-- 修改定时任务
alter event lock_rpt
on schedule every 20 second
do
update rpt_template set report_status=1 where rpt_template_id = '000'
-- Modify the scheduled task format
alter event 事件名称
on schedule every 间隔时间
do
具体执行的SQL任务语句
-- View specified events
show events
-- 或
select * from mysql.event
-- Closes the scheduled task for the specified event
alter event lock_rpt on completion preserve disable
-- 关闭定时器
set global event_scheduler = 0
*开启事件
The above opens the event,数据库重启后,The event button closes automatically,如果想永久改变,参考鸡蛋(我大学室友)写的:
https://blog.csdn.net/qq_38134242/article/details/114300600?spm=1001.2014.3001.5501
中的1.2.2
可视化方式
1.使用Navicat,Select the corresponding database,右击事件,新建事件
2.Double-click the event to open it,Write what the event needs to execute in the definitionSQL
3.Set the execution start time and frequency of this event,最后保存,保存的时候,The name to enter for this event
4.Where events are actually stored(MySQL数据库中的event表)
边栏推荐
猜你喜欢
随机推荐
基于 JSch 实现服务的自定义监控解决方案
零搜索量的关键词,你需要布局吗?
MySQL事件_单次事件_定时循环事件
100句话,是否会触动你?
elder blind date
Makefile中patsubst、wildcard、notdir的使用
BUUCTF MISC brush notes (2)
政务中心导航定位系统,让高效率办事成为可能
centos7 mysql异常ERROR 2002 (HY000)分析解决
Swap swap partition
【Harmony OS】【ArkUI】ets开发 简易视频播放器
AES/ECB/PKCS5Padding加解密
Anaconda4.8.3介绍、安装及使用教程安装(win10)并修改Jupyter默认工作目录
MySQL Leak Detection and Filling (3) Calculated Fields
Where does detection go forward?
【环境搭建】onnx-tensorrt
C#学习笔记
Calendar类和Date类转换时区 && 部分时区城市列表
小程序/app触底加载更多数据
Arduino+2片74hc595 驱动8x8(共阳)点阵(1008BS)