当前位置:网站首页>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 ON
View 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 tasks
Four, 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()
边栏推荐
- [Server installation Redis] Centos7 offline installation of redis
- MQ框架应用比较
- 二叉堆的基础~
- [Likou] 22. Bracket generation
- [FPGA] day19- binary to decimal (BCD code)
- Get Qt installation information: including installation directory and various macro addresses
- Mysql:设置主键自动增长起始值
- jwsManager服务接口实现类-jni实现
- 关于pom.xml文件
- (转)JVM中那些区域会发生OOM?
猜你喜欢
"104 Maximum Depth of Binary Trees" in LeetCode's Day 12 Binary Tree Series
我的LaTeX入门
Object Creation and Display Transformation
leetcode刷题第13天二叉树系列之《98 BST及其验证》
WPF DataGrid 使用数据模板(2)
LeetCode刷题第11天字符串系列之《 58最后一个单词长度》
LeetCode刷题第16天之《239滑动窗口最大值》
Harvesting of radio frequency energy
[FPGA] Design Ideas - I2C Protocol
0基础转行软件测试,自学3个月,浅拿12k*13薪offer
随机推荐
交换机--- 生成树--三层架构总结
Solve the problem of multi-thread calling sql stored procedure
.NET 服务注册
Day20 FPGA 】 【 - block the I2C read and write EEPROM
洛谷P4324 扭动的回文串
如何缓解压力、拒绝内耗【1】
How to add icons to web pages?
洛谷P6586 蒟蒻火锅的盛宴
uni-app - city selection index list / city list sorted by A-Z (uview component library IndexList index list)
使用百度EasyDL实现森林火灾预警识别
(转)JVM中那些区域会发生OOM?
Switch---Spanning Tree---Three-layer Architecture Summary
MySQL database storage engine and database creation, modification and deletion
send_sig: 内核执行流程
Dry goods: The principle and practice of server network card group technology
What is ensemble learning in machine learning?
优先级队列
JVM 垃圾回收的概述与机制
Clang Code Model: Error: The clangbackend executable “X:/clangbackend.exe“ could not be started
【服务器安装mysql】centos7下使用mysql离线安装包安装mysql5.7