mysql定时任务
程序员文章站
2022-07-06 13:37:44
定时刷新mysql某个表的字段,在0,1,2之间切换建表numberCREATE TABLE `number` ( `id` int DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;创建存储过程CREATE DEFINER=`root`@`localhost` PROCEDURE `NewProc`( )BEGIN#Routine body goes here...DECLARE...
定时刷新mysql某个表的字段,在0,1,2之间切换
建表number
CREATE TABLE `number` (
`id` int DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
创建存储过程
CREATE DEFINER=`root`@`localhost` PROCEDURE `NewProc`( )
BEGIN#Routine body goes here...
DECLARE
num INT DEFAULT 0;
SELECT
id INTO num
FROM
number;
IF
num = 0 THEN
UPDATE number
SET id = 1;
ELSEIF num = 1 THEN
UPDATE number
SET id = 2;
ELSEIF num = 2 THEN
UPDATE number
SET id = 0;
END IF;
END
创建事件
填写需要执行的存储过程
call NewProc()
设定计划,从何时开始,每隔多久执行一次
最后每隔五秒查询一次number表就可以发现字段id不断在0,1,2之间切换
本文地址:https://blog.csdn.net/qq_23355059/article/details/108981217