MySQL定时器EVENT学习笔记_MySQL
程序员文章站
2024-02-17 18:24:16
...
bitsCN.com
要使定时起作用 MySQL的常量GLOBAL event_scheduler必须为on或者是1
-- 查看是否开启定时器
SHOW VARIABLES LIKE '%sche%';
-- 开启定时器 0:off 1:on
SET GLOBAL event_scheduler = 1;
-- 创建事件
--每隔一秒自动调用e_test()存储过程
CREATE EVENT IF NOT EXISTS event_test
ON SCHEDULE EVERY 1 SECOND
ON COMPLETION PRESERVE
DO CALL e_test();
-- 开启事件
ALTER EVENT event_test ON
COMPLETION PRESERVE ENABLE;
-- 关闭事件
ALTER EVENT event_test ON
COMPLETION PRESERVE DISABLE;
SELECT * FROM t;bitsCN.com
-- 查看是否开启定时器
SHOW VARIABLES LIKE '%sche%';
-- 开启定时器 0:off 1:on
SET GLOBAL event_scheduler = 1;
-- 创建事件
--每隔一秒自动调用e_test()存储过程
CREATE EVENT IF NOT EXISTS event_test
ON SCHEDULE EVERY 1 SECOND
ON COMPLETION PRESERVE
DO CALL e_test();
-- 开启事件
ALTER EVENT event_test ON
COMPLETION PRESERVE ENABLE;
-- 关闭事件
ALTER EVENT event_test ON
COMPLETION PRESERVE DISABLE;
SELECT * FROM t;bitsCN.com