当前位置:网站首页>Events and scheduled tasks in Mysql
Events and scheduled tasks in Mysql
2022-08-11 04:39:00 【Invincible Odada】
I. Introduction
Event is a procedural database object called by MySQL at the corresponding moment.It is a tool of MYSQL. An event can be called once or started periodically. It is managed by a specific thread, which is the so-called "event scheduler".
Second, create grammar
CREATE
[DEFINER = { user | CURRENT_USER }]
EVENT
[IF NOT EXISTS]
event_name
ON SCHEDULE schedule
[ON COMPLETION [NOT] PRESERVE]
[ENABLE | DISABLE | DISABLE ON SLAVE]
[COMMENT 'comment']
DO event_body;
schedule:
AT timestamp [+ INTERVAL interval] ...
| EVERY interval
[STARTS timestamp [+ INTERVAL interval] ...]
[ENDS timestamp [+ INTERVAL interval] ...]
interval:
quantity {YEAR | QUARTER |MONTH | DAY | HOUR | MINUTE |
WEEK | SECOND | YEAR_MONTH | DAY_HOUR | DAY_MINUTE |
Glossary
event_name : The name of the created event (uniquely determined).
ON SCHEDULE: Scheduled tasks.
schedule: Determine the execution time and frequency of the event (note that the time must be in the future, the past time will be wrong), there are two forms AT and EVERY.
[ON COMPLETION [NOT] PRESERVE]: Optional, the default is ON COMPLETION NOT PRESERVE, that is, the event will be automatically dropped after the scheduled task is executed; ON COMPLETION PRESERVE will not drop it.
[COMMENT 'comment'] : optional, comment is used to describe the event; quite a comment, the maximum length is 64 bytes.
[ENABLE | DISABLE]: Set the state of the event, the default ENABLE: means that the system tries to execute the event, DISABLE: close the event, you can modify it with alter
DO event_body: the SQL statement to be executed (can be a compoundstatement).CREATE EVENT is legal when used in a stored procedure.
Three, open and close the event scheduler
1. Check if it is turned on
show variables like '%event_scheduler%';The default is off, not enabled
2. Open the event scheduler
SET GLOBAL event_scheduler = ON;SET @@global.event_scheduler = ON;SET GLOBAL event_scheduler = 1;SET @@global.event_scheduler = 1;Or through the configuration file my.cnf
event_scheduler = 1 #or ONView scheduler threads:
show processlist; 3, close the event scheduler
SET GLOBAL event_scheduler = OFF;SET @@global.event_scheduler = OFF;SET GLOBAL event_scheduler = 0;SET @@global.event_scheduler = 0;4. View scheduler thread tasks
SELECT @@event_scheduler;SHOW PROCESSLIST;show events; #View the current schema scheduling tasksselect * from mysql.event;#View the entire database scheduling tasksFour, create a test table
1. Simple omission
2. Create event 1 (start the event immediately)
create event event_nowon scheduleat now()do insert into events_list values('event_now', now());3. Create event 2 (start event every minute)
create event test.event_minuteon scheduleevery 1 minutedo insert into events_list values('event_now', now());4. Create event 3 (start event every second)
CREATE event event_nowON SCHEDULEEVERY 1 SECONDDO INSERT INTO event_test VALUES(1);5. Create event 4 (call the stored procedure every second)
CREATE DEFINER=`root`@`localhost` EVENT `eventUpdateStatus`ON SCHEDULE EVERY 1 SECONDSTARTS '2017-11-21 00:12:44'ON COMPLETION PRESERVEENABLEDO call updateStatus()边栏推荐
- MYSQLg advanced ------ return table
- "104 Maximum Depth of Binary Trees" in LeetCode's Day 12 Binary Tree Series
- Self-research capability was recognized again, and Tencent Cloud Database was included in the Forrester Translytical report
- 无线电射频能量的收集
- 洛谷P2370 yyy2015c01 的 U 盘
- Dry goods: The principle and practice of server network card group technology
- About the pom.xml file
- LeetCode Brush Questions Day 11 String Series "58 Last Word Length"
- 【力扣】22.括号生成
- What is ensemble learning in machine learning?
猜你喜欢

【FPGA】day21- moving average filter

移动端地图开发选择哪家?

【力扣】22.括号生成

Self-research capability was recognized again, and Tencent Cloud Database was included in the Forrester Translytical report

【人话版】WEB3将至之“权益的游戏”
![[Likou] 22. Bracket generation](/img/f6/435fe9e0b4c1545514d1bf195ffd44.png)
[Likou] 22. Bracket generation

leetCode刷题14天二叉树系列之《 110 平衡二叉树判断》

一文读懂 高性能可预期数据中心网络

快速使用UE4制作”大场景游戏“

《卫星界》刊评“星辰大海”计划:孙宇晨为太空旅游带来新的机遇
随机推荐
洛谷P7441 Erinnerung
Redis: Solve the problem of modifying the same key with distributed high concurrency
使用jackson解析json数据详讲
The basics of binary heap~
「转」“搜索”的原理,架构,实现,实践,面试不用再怕了
0 Basic software test for career change, self-study for 3 months, 12k*13 salary offer
破解事务性工作瓶颈,君子签电子合同释放HR“源动力”!
校园兼职平台项目反思
.NET 服务注册
源代码加密技术浅析
Three 】 【 yolov7 series of actual combat from 0 to build training data sets
About the pom.xml file
视觉任务种常用的类别文件之一json文件
How to add icons to web pages?
[Actual combat scene] Mall-discount event design plan
【FPGA】day21- moving average filter
LeetCode刷题第16天之《239滑动窗口最大值》
leetcode刷题第13天二叉树系列之《98 BST及其验证》
Bubble sort and heap sort
使用百度EasyDL实现智能垃圾箱