首页 >数据库 >mysql教程 >mysql定时任务与存储过程实例_MySQL

mysql定时任务与存储过程实例_MySQL

WBOY
WBOY原创
2016-06-01 13:17:321182浏览

/**查看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()

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn