mysql定时任务设置

来源:转载

Navicat设置MySQL定时事件参考: 1. http://blog.csdn.net/zzhongcy/article/details/419479272. http://www.mamicode.com/info-detail-1040270.html3. http://www.cnblogs.com/chenpi/p/5137310.html1. 创建事件选择对应数据库->'事件'->'新建事件'2. 定义事件2.1 定义SQL语句: 以BEGIN开头,以END结尾BEGINDELETE FROM goods WHERE endtime <= CURDATE();END2.2 定义者: [email protected]如果是在本地运行,Definer为[email protected] 状态: ENABLE(激活)/DISABLE(不激活)2.4 ON COMPLETION正常情况下,一旦事件已过期,它将立即删除。你可以通过指定 ON COMPLETION PRESERVE 来重写此性能。使用 ON COMPLETION NOT PRESERVE 只是使默认非持久性的性能明确3. 计划3.1 AT: 用于一次性事件3.2 EVERY: 在定期间隔重复的行动4. 事件SQLCREATE DEFINER=`root`@`localhost`EVENT `NewEvent`ON SCHEDULE EVERY 1 DAY STARTS '2017-05-28 00:00:00'ON COMPLETION NOT PRESERVEENABLEDOBEGINDELETE FROM goods WHERE endtime <= CURDATE();END;5. 查看事件状态查看事件是否开启: show variables like 'event_scheduler';6. 开启/关闭事件语句6.1 开启: set global event_scheduler = on;7. 让MySQL服务启动时开启时间只需要在my.ini配置文件的[mysqld]部分加上event_scheduler=ON 即可8. 事件示例:DROP EVENT IF EXISTS `event_minute`;DELIMITER ;;CREATE DEFINER=`root`@`localhost` EVENT `event_minute` ON SCHEDULE EVERY 1 MINUTE STARTS '2016-01-17 14:49:43' ON COMPLETION NOT PRESERVE ENABLE DO
BEGININSERT INTO USER(name, address,addtime) VALUES('test1','test1',now());INSERT INTO USER(name, address,addtime) VALUES('test2','test2',now());END;;DELIMITER ;

分享给朋友:
您可能感兴趣的文章:
随机阅读: