- -- 查看是否开启定时器
- 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 5 SECOND
- ON COMPLETION PRESERVE
- DO INSERT INTO `zanbao`.`sequence` (`name`, `current_value`, `increment`) VALUES ('20150409', '0', '1');
- -- DO CALL e_test();
- -- date_format(now(),'%Y%m%d')
- -- 开启事件
- ALTER EVENT event_test ON COMPLETION PRESERVE ENABLE;
- -- 关闭事件
- ALTER EVENT event_test ON COMPLETION PRESERVE DISABLE;
- CREATE DEFINER=`root`@`localhost` PROCEDURE `init_order_date`()
- BEGIN
- DECLARE a INT DEFAULT 365;
- DECLARE b INT DEFAULT 0;
- set autocommit = 0;
- WHILE (b<a) DO
- INSERT INTO `zanbao`.`sequence` (`name`, `current_value`, `increment`) VALUES (date_format(date_add('2015-04-08', interval 24*b hour),'%Y%m%d'), '0', '1');
- SET b = b + 1;
- END WHILE;
- commit;
- END