日期:2014-05-16  浏览次数:20883 次

mysql binlog清理

不知道你有没有为mysql的binlog占用大量磁盘感到无奈,my.cnf里binlog的size可以设置多大做分割,但没有看到删除的配置,在mysql里show了一下variables,

mysql> show variables like 'expire_logs_days%';
+------------------+-------+
| Variable_name??? | Value |
+------------------+-------+
| expire_logs_days | 10??? |
+------------------+-------+
1 row in set (0.00 sec)

这个默认是0,也就是logs不过期,现在是10天也有点长了,推荐3天
set global expire_logs_days=3;

查看bin log
mysql> show binary logs;
+------------------+-----------+
| Log_name???????? | File_size |
+------------------+-----------+
| mysql-bin.003264 | 104857665 |
| mysql-bin.003265 | 104858206 |
| mysql-bin.003266 | 104857901 |
| mysql-bin.003267 | 104857830 |
| mysql-bin.003268 | 104858231 |
| mysql-bin.003269 | 104857656 |
| mysql-bin.003270 | 104857646 |
| mysql-bin.003271 | 104858180 |
| mysql-bin.003272 | 104857905 |
| mysql-bin.003273 | 104857839 |
| mysql-bin.003274 | 104858611 |

通过purge binary logs to删除,003270之前的会被delete掉
purge binary logs to 'mysql-bin.003270';