标签:style blog http io color ar os 使用 for
一、前言
SET GLOBAL event_scheduler = 1;
---或我们可以在配置my.ini文件 中加上
event_scheduler = 1
SET GLOBAL event_scheduler = ON;
mysqld ... --event_scheduler=1
SHOW VARIABLES LIKE ‘event_scheduler‘;
SELECT @@event_scheduler;
SHOW PROCESSLIST;
CREATE EVENT [IF NOT EXISTS] event_name ON SCHEDULE schedule [ON COMPLETION [NOT] PRESERVE] [ENABLE | DISABLE] [COMMENT ‘comment‘] DO sql_statement; schedule: AT TIMESTAMP [+ INTERVAL INTERVAL] | EVERY INTERVAL [STARTS TIMESTAMP] [ENDS TIMESTAMP] INTERVAL: quantity {YEAR | QUARTER | MONTH | DAY | HOUR | MINUTE | WEEK | SECOND | YEAR_MONTH | DAY_HOUR | DAY_MINUTE | DAY_SECOND | HOUR_MINUTE | HOUR_SECOND | MINUTE_SECOND}
USE test; CREATE TABLE aaa (timeline TIMESTAMP); CREATE EVENT e_test_insert ON SCHEDULE EVERY 1 SECOND DO INSERT INTO test.aaa VALUES (CURRENT_TIMESTAMP);
mysql> SELECT * FROM aaa; +---------------------+ | timeline | +---------------------+ | 2007-07-18 20:44:26 | | 2007-07-18 20:44:27 | | 2007-07-18 20:44:28 | +---------------------+
CREATE EVENT e_test ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 5 DAY DO TRUNCATE TABLE test.aaa;
CREATE EVENT e_test ON SCHEDULE AT TIMESTAMP ‘2007-07-20 12:00:00‘ DO TRUNCATE TABLE test.aaa;
CREATE EVENT e_test ON SCHEDULE EVERY 1 DAY DO TRUNCATE TABLE test.aaa;
CREATE EVENT e_test ON SCHEDULE EVERY 1 DAY STARTS CURRENT_TIMESTAMP + INTERVAL 5 DAY DO TRUNCATE TABLE test.aaa;
CREATE EVENT e_test ON SCHEDULE EVERY 1 DAY ENDS CURRENT_TIMESTAMP + INTERVAL 5 DAY DO TRUNCATE TABLE test.aaa;
CREATE EVENT e_test ON SCHEDULE EVERY 1 DAY STARTS CURRENT_TIMESTAMP + INTERVAL 5 DAY ENDS CURRENT_TIMESTAMP + INTERVAL 1 MONTH DO TRUNCATE TABLE test.aaa;
CREATE EVENT e_test ON SCHEDULE EVERY 1 DAY ON COMPLETION NOT PRESERVE DO TRUNCATE TABLE test.aaa;
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 e_test DISABLE;
ALTER EVENT e_test ENABLE;
ALTER EVENT e_test ON SCHEDULE EVERY 5 DAY;
DROP EVENT [IF EXISTS] event_name
DROP EVENT e_test;
DROP EVENT IF EXISTS e_test; 注意:如果你将event执行了Alter event event_name disable.那么当你重新启动mysql服务 器后,该event将被删除(测试版本:5.1.30)
delimiter // create procedure `Slave_Monitor`() begin SELECT VARIABLE_VALUE INTO @SLAVE_STATUS FROM information_schema.GLOBAL_STATUS WHERE VARIABLE_NAME=‘SLAVE_RUNNING‘; IF (‘ON‘ != @SLAVE_STATUS) THEN SET GLOBAL SQL_SLAVE_SKIP_COUNTER=0; SLAVE START; END IF; end; // delimiter ;
CREATE EVENT IF NOT EXISTS `Slave_Monitor` ON SCHEDULE EVERY 5 SECOND ON COMPLETION PRESERVE DO CALL Slave_Monitor();
创建了一个任务,每 5秒钟执行一次,任务结束后依旧保留该任务,而不是删除。当然了,在本例中的任务不会结束,除非将它手动禁止了。
(root:localhost:)test> alter event `Slave_Monitor` ON COMPLETION PRESERVE DISABLE; (root:localhost:)test> alter event `Slave_Monitor` ON COMPLETION PRESERVE ENABLE;
标签:style blog http io color ar os 使用 for
原文地址:http://www.cnblogs.com/yu-zhang/p/4076379.html