/** 查看event是否開啟 : SHOW VARIABLES LIKE '%event_sche%'; 將事件計劃開啟 : SET GLOBAL event_scheduler = 1; 將事件計劃關閉 : SET GLOBAL event_scheduler = 0; 關閉事件任務 : ALTER EVENT eventName ON COMPLETION PRESERVE DISABLE; 開啟事件任務 : ALTER EVENT eventName ON COMPLETION PRESERVE ENABLE; 查看事件任務 : SHOW EVENTS ; delimiter // 設定語句終結符為 //,因存儲過程語句用;結束 **/ DROP TABLE IF EXISTS test; CREATE TABLE test ( id bigint(11) unsigned NOT NULL AUTO_INCREMENT, name varchar(100) NOT NULL DEFAULT '', create_time datetime, PRIMARY KEY (ID) ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; DELIMITER // DROP PROCEDURE IF EXISTS p_test// CREATE PROCEDURE p_test() BEGIN INSERT INTO test(name, create_time) values('testName', now()); END// DROP EVENT IF EXISTS e_test// CREATE EVENT e_test ON SCHEDULE EVERY 10 second STARTS TIMESTAMP '2014-04-09 01:00:00' ON COMPLETION PRESERVE DO BEGIN CALL p_test(); END//
以上事件e_test表示每10秒執行一次p_test()