事件調度器是在 MySQL
事件調度器是定時觸發執行的
(root:localhost:)test> SET GLOBAL event_scheduler = ON;
(root:localhost:)test> show processlist\G
***************************row ***************************
Id:
User: event_scheduler
Host: localhost
db: NULL
Command: Daemon
Time:
State: Waiting on empty queue
Info: NULL
如上
應用案例
本案例是利用 event scheduler 的特性
首先創建存儲過程
delimiter //
create procedure `Slave_Monitor`()
beginSELECT VARIABLE_VALUE INTO @SLAVE_STATUS
FROM information_schemaGLOBAL_STATUS
WHERE VARIABLE_NAME=SLAVE_RUNNING ; IF (
ON != @SLAVE_STATUS) THEN
SET GLOBAL SQL_SLAVE_SKIP_COUNTER=;
SLAVE START;
END IF;end; //
delimiter ;
由於存儲過程中無法調用類似 SHOW SLAVE STATUS 這樣的語句
接著
CREATE EVENT IF NOT EXISTS `Slave_Monitor`
ON SCHEDULE EVERY
ON COMPLETION PRESERVE
DO
CALL Slave_Monitor();
創建了一個任務
如果在運行中想要臨時關閉一下某個任務
(root:localhost:)test> alter event `Slave_Monitor` ON
COMPLETION PRESERVE DISABLE;
(root:localhost:)test> alter event `Slave_Monitor` ON
COMPLETION PRESERVE ENABLE;
From:http://tw.wingwit.com/Article/program/MySQL/201404/30554.html