当前位置:网站首页>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()
边栏推荐
- send_sig: kernel execution flow
- 洛谷P4560 Wall 砖墙
- 【FPGA】day22-SPI protocol loopback
- [Server installation mysql] Use mysql offline installation package to install mysql5.7 under centos7
- Redis:解决分布式高并发修改同一个Key的问题
- shell监视gpu使用情况
- Common layout effect realization scheme
- 直播平台开发,Flutter,Drawer侧滑
- 洛谷P2245 星际导航
- 洛谷P7441 Erinnerung
猜你喜欢
「转」“搜索”的原理,架构,实现,实践,面试不用再怕了
Self-research capability was recognized again, and Tencent Cloud Database was included in the Forrester Translytical report
How to learn machine learning?machine learning process
Three 】 【 yolov7 series of actual combat from 0 to build training data sets
移动端地图开发选择哪家?
How to add icons to web pages?
"3 Longest Substring Without Repeating Characters" on the 17th day of LeetCode brushing
如何给网页添加icon图标?
这些云自动化测试工具值得拥有
What is machine learning?Explain machine learning concepts in detail
随机推荐
[FPGA] day19- binary to decimal (BCD code)
Mysql: set the primary key to automatically increase the starting value
力扣——旋转数组的最小数字
快速使用UE4制作”大场景游戏“
I wrote some code in my resume, but I still can't pass the interview
洛谷P5139 z小f的函数
Which one to choose for mobile map development?
[Note] Is the value of BatchSize the bigger the better?
Mysql中事件和定时任务
【人话版】WEB3将至之“权益的游戏”
LeetCode刷题第16天之《239滑动窗口最大值》
shell monitors gpu usage
简历里写了会代码,却依然过不了面试这一关
使用百度EasyDL实现森林火灾预警识别
Dry goods: The principle and practice of server network card group technology
C# 一周入门高级编程之《C#-LINQ》Day Four
JVM 垃圾回收的概述与机制
What is Machine Reinforcement Learning?What is the principle?
Read the article, high-performance and predictable data center network
Use jackson to parse json data in detail