//创建定时器每隔5s向表中插入一条记录
drop table if exists event_test;
create table event_test(
id int not null auto_increment,
update_tm timestamp,
create_tm timestamp,
primary key(id)
);
-- 定时器周期性插入数据
drop event if EXISTS timer_event;
delimiter //
create event timer_event on schedule every 5 second
do
begin
insert into event_test(id, update_tm, create_tm) values (NULL, now(), now());
end;
//
delimiter;
-- 定时器可以周期性调用存储过程
drop event if EXISTS timer_event;
create event timer_event on schedule every 5 second
do call my_procedure();
#若定时器没有开启,需要开启,若数据库重启会出现默认关闭,
#则需要在配置.cnf文件中对event_scheduler = on进行配置
show variables like '%event%'
set global event_scheduler = on
mysql创建定时器
最新推荐文章于 2023-06-30 09:10:24 发布