zoukankan      html  css  js  c++  java
  • mysql purge master logs to binlog

    max_binlog_files,是Percona MySQL分支提供的限制binlog文件数量的参数,在删除归档数据、binlog增长很快的情况下,很实用的一个参数。

    该参数也对正在被使用的binlog提供了保护,是purge不掉的.

    手动执行PURGE MASTER LOGS操作,发现执行速度很快,但存在WARNING:

    +---------+------+-----------------------------------------------------------------------------------------------------------------+
    | Level   | Code | Message                                                                                                         |
    +---------+------+-----------------------------------------------------------------------------------------------------------------+
    | Warning | 1867 | file ./mysql-bin.011530 was not purged because it was being read by 1 thread(s), purged only 0 out of 51 files. |
    +---------+------+-----------------------------------------------------------------------------------------------------------------+

    在使用PURGE MASTER LOGS清理BINLOG时,如果还有活跃从库需要访问这些BINLOG,那么PURGE会失效。

    通过SHOW PROCESSLIST可以发现:

    *************************** 11. row ***************************
         Id: 6629525
       User: magpie
       Host: xxx.xxx.xxx.xxx:62054
         db: NULL
    Command: Binlog Dump
       Time: 283180
      State: Sending to client
       Info: NULL

    而283180/60/60=3.27,即该进程处于“Sending to client”已经3天,查看最早BINLOG也是3天前的,因此可以断定由该进程引起,手动KILL该进程并再次运行PURGE MASTER LOGS,发现BINLOG被正常清理。

    删除binlog命令:

    --清除MySQL-bin.010日志
    mysql> PURGE MASTER LOGS TO 'MySQL-bin.010';
     
    --清除2008-06-22 13:00:00前binlog日志
    mysql> PURGE MASTER LOGS BEFORE '2008-06-22 13:00:00';   
     
    --清除3天前binlog日志BEFORE,变量的date自变量可以为'YYYY-MM-DD hh:mm:ss'格式。
    mysql> PURGE MASTER LOGS BEFORE DATE_SUB( NOW(), INTERVAL 3 DAY); 
  • 相关阅读:
    Codeforces Round #439 (Div. 2)
    Money Systems
    Stamps
    inflate
    多重背包问题
    AIM Tech Round 4 (Div. 2)
    September Challenge 2017
    树的重心
    百度之星2017初赛A
    树上的最大独立集
  • 原文地址:https://www.cnblogs.com/hankyoon/p/14416125.html
Copyright © 2011-2022 走看看