要查看當前是否已開啟事件調度器
SHOW VARIABLES LIKE 'event_scheduler';
開啟事件檢視器
SET GLOBAL event_scheduler = 1;
建立事件
文法:
CREATE EVENT [IF NOT EXISTS] event_name
ON SCHEDULE schedule
[ON COMPLETION [NOT] PRESERVE]
[ENABLE | DISABLE]
[COMMENT 'comment']
DO sql_statement;
執行個體:
CREATE EVENT updateInfoStatus
ON SCHEDULE EVERY 30 MINUTE
DO
UPDATE `jd_article` SET `status` = 0 WHERE `status` = 1 AND `date` <= now( );
修改事件
文法:
ALTER EVENT event_name
[ON SCHEDULE schedule]
[RENAME TO new_event_name]
[ON COMPLETION [NOT] PRESERVE]
[COMMENT 'comment']
[ENABLE | DISABLE]
[DO sql_statement]
執行個體:
ALTER EVENT updateInfoStatus
ON SCHEDULE EVERY 30 MINUTE
DO
UPDATE `jd_article` SET `status` = 0 WHERE `status` = 1 AND `date` <= now( );
刪除事件
DROP EVENTS IF EXISTS updateInfoStatus
臨時關閉事件
ALTER EVENTS updateInfoStatus DISABLE
開啟事件
ALTER EVENTS updateInfoStatus ENABLE
查看事件詳細資料
SELECT * FROM INFORMATION_SCHEMA.EVENTS WHERE EVENT_NAME = 'updateInfoStatus' AND EVENT_SCHEMA = 'jdwc'
查看所有事件
SHOW EVENTS
查看事件建立資訊
SHOW CREATE EVENT updateInfoStatus
作者 Zhou Hr