Home > Database > Mysql Tutorial > body text

mysql事件调度器定时删除binlog_MySQL

WBOY
Release: 2016-06-01 13:18:08
Original
956 people have browsed it

bitsCN.com MySQL5.1.6起Mysql增加了事件调度器(Event Scheduler),可以用做定时执行某些特定任务,来取代原先只能由Linux操作系统的计划任务来执行的工作MySQL的事件调度器可以精确到每秒钟执行一个任务,对于一些对数据实时性要求比较高的应用(例如:股票、赔率、比分等)就非常适合。
先查看是否启动这个功能:
代码如下:SELECT @@event_scheduler;
在使用这个功能之前必须确保 event_scheduler已开启,可执行:
代码如下:SET GLOBAL event_scheduler = 1;
或我们可以在配置my.cnf文件 中加上event_scheduler = 1
然后来对 binlog 的删除写一个事件.设置天检查,并删除每 4 天前的 binlog 文件.
代码如下:CREATE EVENT purge_binlog ON SCHEDULE EVERY 1 DAY DO PURGE MASTER LOGS BEFORE DATE_SUB( NOW( ), INTERVAL 4 DAY);
查看定时事件可以,通过执行如下的语句:
代码如下:SELECT *  FROM information_schema.EVENTS;
可以看到相应的库中的作业信息,其中LAST_EXECUTED字段会反映出相应的作业最近一次的执行时间。bitsCN.com

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!