要让JOB顺利运行,必须要打开MYSQL的定时器。

-- 查看是否开启定时器
SHOW VARIABLES LIKE '%sche%'; -- 开启定时器 0:off 1:on
-- 这个需要最高权限打开,否则会提示(无权限):you need (at least one of) the CREATE USER privilege(s) for this operation
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;
05-07 15:55