Tibor's Musings

MySQL Replication Purging

How to purge old unnecessary MySQL binary log files on DB master, after checking replication status.

On DB master (PCUDSSX1501), did:

mysql> SHOW MASTER STATUS;
+------------------+----------+--------------+------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000075 |   277790 |              |                  |
+------------------+----------+--------------+------------------+

On DB slave (PCUDSSW1513), did:

mysql> SHOW SLAVE STATUS\G;
*************************** 1. row ***************************
             Slave_IO_State:
                Master_Host: 137.138.198.204
                Master_User: repl
                Master_Port: 3306
              Connect_Retry: 60
            Master_Log_File: mysql-bin.000063
        Read_Master_Log_Pos: 399760643
             Relay_Log_File: mysqld-relay-bin.000191
              Relay_Log_Pos: 235
      Relay_Master_Log_File: mysql-bin.000063
        Exec_Master_Log_Pos: 399760643

As one can see, DB slave uses binary log file mysql-bin.000063. Hence we can clean all previous DB master log files up to that one.

On DB master (PCUDSSX1501), did:

mysql> PURGE MASTER LOGS TO 'mysql-bin.000063';
Query OK, 0 rows affected, 13 warnings (1 min 1.80 sec)

This liberates quite a considerable disk space. (About 1 GB per binary log file.)

mysql