1 前言
利用navicat工具来写存储过程及定时执行
2 步骤
2.1 新建过程
2.2 在函数体写你需要执行的代码
CREATE DEFINER=`root`@`localhost` PROCEDURE `test`()
BEGIN
#Routine body goes here...
#DECLARE a int;
SET @time = NOW();
SET @item = 'num';
SET @type = 'day';
select content into @content from rank where uid = 123456 and num >0;
INSERT INTO rank2(time,item,type,content) VALUES(@time,@item,@type,@content);
UPDATE rank SET num=0 WHERE userid >0;
END
2.3 创建一个事件
2.3.1 新建事件
2.3.3 填写你定时计划
代码预览如下:
CREATE EVENT `nodejs`.`Untitled`
ON SCHEDULE
EVERY '1' DAY STARTS '2018-07-25 00:00:00'
DO call test();
3 异常
如果发现,你步骤都设置完了,还没有起作用,那可能是定时器开关没打开。
查看是否有开启,方法 show variables like ‘event%’;
如果是OFF,则用SET GLOBAL event_scheduler = 1;或者SET GLOBAL event_scheduler = ON;开启。开启后其Value则为ON。
参考:https://www.cnblogs.com/fanbi/p/9361204.html