MySQL主從同步日志清理


-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

自動清除配置

  vim /etc/my.cnf
    #二進制日志自動刪除的天數。默認值為0,表示“沒有自動刪除” #一般將x設置為短點,如10

    expire_logs_days = x

    #此方法需要重啟mysql,附錄有關於expire_logs_days的英文說明 當然也可以不重啟mysql,開啟mysql主從,直接在mysql里設置expire_logs_days
      > show binary logs;
      > show variables like '%log%';
      > set global expire_logs_days = 10;

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

手動刪除

  > PURGE MASTER LOGS BEFORE DATE_SUB(CURRENT_DATE, INTERVAL 10 DAY); //刪除10天前的MySQL binlog日志,附錄2有關於PURGE MASTER LOGS手動刪除用法及示例
  > show master logs;

 

擴展
1.expire_logs_days英文說明
  Where X is the number of days you’d like to keep them around.

   I would recommend 10, but this depends on how busy your MySQL server is and how fast these log files grow.

  Just make sure it is longer than the slowest slave takes to replicate the data from your master.

  Just a side note: You know that you should do this anyway, but make sure you back up your mysql database.

  The binary log can be used to recover the database in certain situations;

  so having a backup ensures that if your database server does crash, you will be able to recover the data.

2.PURGE MASTER LOGS手動刪除用法及示例,MASTER和BINARY是同義詞
  > PURGE {MASTER | BINARY} LOGS TO 'log_name'
  > PURGE {MASTER | BINARY} LOGS BEFORE 'date'
  刪除指定的日志或日期之前的日志索引中的所有二進制日志。這些日志也會從記錄在日志索引文件中的清單中被刪除MySQL BIN-LOG 日志,這樣被給定的日志成為第一個。

  實例:
  > PURGE MASTER LOGS TO 'MySQL-bin.010'; //清除MySQL-bin.010日志
  > PURGE MASTER LOGS BEFORE '2008-06-22 13:00:00'; //清除2008-06-22 13:00:00前binlog日志
  > PURGE MASTER LOGS BEFORE DATE_SUB( NOW( ), INTERVAL 3 DAY); //清除3天前binlog日志BEFORE,變量的date自變量可以為'YYYY-MM-DD hh:mm:ss'格式。

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM