MySQL 手動清除binlog

新接手的四套庫MySQL庫,採用主從結構。之前配置的夥計備庫的bin log 日誌全部是打開狀態。運維人員反映,空間告警幾次。均手動上去處理。


備庫開啓了bin log 也影響備庫的性能,雖然這四套MySQL庫的壓力不大,但是本着優化的態度,還是對這四套庫做一次徹底的清楚。


1.  查看備庫當前的bin log:


show binary logs;


直接刷出了七百多個bin - log。從上線之初到現在一年時間, 只有1T的bin log


2. 查看備庫的slave 運行狀態

show slave status\G

*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 10.180.213.58
                  Master_User: rep581
                  Master_Port: 3301
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000266
          Read_Master_Log_Pos: 429863077
               Relay_Log_File: mysql-relay-bin.000780
                Relay_Log_Pos: 429863287
        Relay_Master_Log_File: mysql-bin.000266
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes

              Replicate_Do_DB: 
          Replicate_Ignore_DB: 
           Replicate_Do_Table: 
       Replicate_Ignore_Table: 
      Replicate_Wild_Do_Table: 
  Replicate_Wild_Ignore_Table: 
                   Last_Errno: 0
                   Last_Error: 
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 429863077
              Relay_Log_Space: 429863578
              Until_Condition: None
               Until_Log_File: 
                Until_Log_Pos: 0
           Master_SSL_Allowed: No
           Master_SSL_CA_File: 
           Master_SSL_CA_Path: 
              Master_SSL_Cert: 
            Master_SSL_Cipher: 
               Master_SSL_Key: 
        Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error: 
               Last_SQL_Errno: 0
               Last_SQL_Error: 
  Replicate_Ignore_Server_Ids: 
             Master_Server_Id: 581
                  Master_UUID: d4d049b3-7151-11e5-972f-000af77f26d8
             Master_Info_File: /mysqldata/mysql2/dat/master.info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
           Master_Retry_Count: 86400
                  Master_Bind: 
      Last_IO_Error_Timestamp: 
     Last_SQL_Error_Timestamp: 
               Master_SSL_Crl: 
           Master_SSL_Crlpath: 
           Retrieved_Gtid_Set: d4d049b3-7151-11e5-972f-000af77f26d8:1-395318788
            Executed_Gtid_Set: d41f98d3-7151-11e5-972f-000af77f26d8:1-471129318,
d4d049b3-7151-11e5-972f-000af77f26d8:1-395318788
                Auto_Position: 1
1 row in set (0.00 sec)


從上面四個指標可以看出備庫運行正常,且沒有任何延遲。因此可以開始手動清理


3. 手動清理,清理原則: 手動清理五天以前的bin log


 PURGE MASTER LOGS BEFORE DATE_SUB(CURRENT_DATE, INTERVAL 5 DAY); 


持續一段時間以後,binglog手動清理完畢。


4. 關閉slave備庫bin log。註銷備庫my.cnf一下參數:

#log-bin = /mysqldata/mysql2/bin/mysql-bin
#sync_binlog = 1
#binlog_cache_size = 4M
#max_binlog_cache_size = 8M
#max_binlog_size = 1024M


最後需要重啓該庫才能夠生效!


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章