Home >Database >Mysql Tutorial >MySQL定时器EVENT学习笔记_MySQL

MySQL定时器EVENT学习笔记_MySQL

WBOY
WBOYOriginal
2016-06-01 13:25:50937browse

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

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn