定时执行存储过程
存储过程
delimiter $
CREATE DEFINER=`root`@`localhost` PROCEDURE `getDaysNum`()
begin
set @num = (select count(*) num from table where date(create_at) = curdate());
insert into table2(num) values(@num);
end
$
delimiter ;
事件(下面中的括号是告诉你设定执行间隔的 你随便取一个括号中的内容就可以了)
CREATE DEFINER=`hihuagent`@`%` EVENT `getDaysNum`
ON SCHEDULE EVERY (1 DAY) || (2 second) || (3 minute) STARTS '2018-03-12 23:59:00'
ON COMPLETION NOT PRESERVE ENABLE DO call `getDaysNum`
开启定时器
set GLOBAL event_scheduler = 1;
查看事件状态
select * from mysql.event
修改事件状态
ALTER EVENT getDaysNum DISABLE; //关闭某事件
ALTER EVENT getDaysNum ENABLE; //开启某事件