mysql定时器

--查看定时器状态
SELECT @@event_scheduler;

--开启定时器
SET GLOBAL event_scheduler = 1;

--2.1、创建测试表test
drop table if exists test;
create table test
(
id int(11) not null auto_increment primary key,
time datetime not null
) engine=innodb default charset=utf8;

--2.2、创建evevt要调用的存储过程test_proce
delimiter //
drop procedure if exists test_proce//
create procedure test_proce()
begin
insert into test(time) values(now());
end//
delimiter ;

--2.4、创建事件test_event(其作用:每隔一秒自动调用test_proce()存储过程)
drop event if exists test_event;
create event test_event
on schedule every 1 second
on completion preserve disable
do call test_proce();

--2.5、开启事件test_event
alter event test_event on completion preserve enable;

--2.6、关闭事件test_event
alter event test_event on completion preserve disable;

--2.7、查看表test
select * from test;

 

posted @ 2019-07-16 22:13  努力挣扎的小兵  阅读(411)  评论(0编辑  收藏  举报