‘%sche%‘;
#如果value显示为off或者0说明是关闭的,这时我们需要手动打开定时器
SET GLOBAL event_scheduler = 1;
#创建测试表
create tabletest
(
idint(11) not null auto_increment primary key,
timedatetime not null) engine=innodb default charset=utf8;
#这是判断我们要执行的文本是否存在,如果存在,就删除这个文本(本质就是我们的定时器定时执行的 代码块)
delimiter //
drop procedure if exists test_proce//#创建event要调用的存储过程test_proce (其实就是创建文本/代码块。)create proceduretest_proce()begin#向test表里面添加当前时间(代码块中的执行命令 我选择的是一个添加,因为容易看到效果)insert into test(time) values(now());end//delimiter ;
#创建事件test_event(其作用:每隔一秒自动调用test_proce()存储过程)
createevent test_event
#这句话是设置时间多长时间执行一次on schedule every 1secondoncompletion preserve disable
#这个是指定要执行的代码块,在上面已经定义过了
do call test_proce();
#2020-01-10 11:10:00启动定时器,每隔12小时执行一次
createevent test_event2on schedule every 12 hour starts timestamp ‘2020-01-10 11:10:00‘
oncompletion preserve disable
do call test_proce();
#开启事件test_event 因为创建的事件的启用属性默认是关闭的,我们将他的属性设置为开启
#就可以使用当前定时器 test_event 是要执行的事件名字
alter event test_event on completion preserve enable;
#关闭事件 test_event 是要关闭的事件名字
alter event test_event on completion preserve disable;
整体流程简介:
1.开启mysql数据库的event功能。
2.创建一个类似于要执行的代码块。
3.创建一个事件,这个事件中有诸多属性,可以设置执行时间间隔以及指定执行的代码块。
4.因为创建的事件的执行属性默认是关闭的,所以我们要去修改这个事件的属性为开启。
mysql定时器
标签:定时器 mysql lte color 测试 null time begin alter
本条技术文章来源于互联网,如果无意侵犯您的权益请点击此处反馈版权投诉
本文系统来源:https://www.cnblogs.com/rong0912/p/12175466.html