34,590
社区成员
发帖
与我相关
我的任务
分享
#增加测试表及测试数据
drop table if exists a;
create table if not exists a(
id int primary key,
c datetime not null,
d int not null
);
truncate table a;
insert into a(id,c,d) values(1,now() -interval 3 hour,0);
insert into a(id,c,d) values(2,now(),0);
#开启事件
SET GLOBAL event_scheduler = ON;
show variables like '%event_scheduler%';
#创建事件 禁用->删除->创建
#alter event `eventTest` disable; #如果有先禁用避免没有生效
drop event if exists `eventTest`;
CREATE EVENT `eventTest`
ON SCHEDULE
EVERY '2' SECOND #测试成功后可改成 Hour
DO update a set d=d+1 where c<now() - interval 2 hour; #具体的逻辑你自己根据需要来修改