MySQL主库删除binlog

随着时间增移,mysql数据库的数据量越来越大,此时可以删除部分没用的binlog以释放部分磁盘。
查看主库binlog:

master-mysql> show binary logs;
+------------+-----------+
| Log_name   | File_size |
+------------+-----------+
| bin.000001 |    152703 |
| bin.000002 |     34150 |
| bin.000003 |    234484 |
| bin.000004 |   1073167 |
| bin.000005 |    540515 |
| bin.000006 |  23231679 |
| bin.000007 |  18464449 |
| bin.000008 |     14699 |
| bin.000009 |     14699 |
| bin.000010 |     43809 |
| bin.000011 |  68827570 |
| bin.000012 |  92119055 |
+------------+-----------+
12 rows in set (0.03 sec)

再从从库查看复制情况:

slave-mysql> show slave status \G
*************************** 1. row ***************************

          Master_Log_File: bin.000012
          Read_Master_Log_Pos: 92128056 
          Seconds_Behind_Master: 0

可见从库已经复制到bin.000012,因此可把bin.000011及其之前的bin文件删除。

master-mysql> show binary logs;
+------------+-----------+
| Log_name   | File_size |
+------------+-----------+
| bin.000001 |    152703 |
| bin.000002 |     34150 |
| bin.000003 |    234484 |
| bin.000004 |   1073167 |
| bin.000005 |    540515 |
| bin.000006 |  23231679 |
| bin.000007 |  18464449 |
| bin.000008 |     14699 |
| bin.000009 |     14699 |
| bin.000010 |     43809 |
| bin.000011 |  68827570 |
| bin.000012 |  92119055 |
+------------+-----------+
12 rows in set (0.03 sec)

master-mysql> purge binary logs to 'bin.000012';
Query OK, 0 rows affected (0.04 sec)

master-mysql> show binary logs;
+------------+-----------+
| Log_name   | File_size |
+------------+-----------+
| bin.000012 |  92173464 |
+------------+-----------+
1 row in set (0.00 sec)

你可能感兴趣的:(mysql)