0


清理MySQL中的binlog

Mysql的binlog开启后一直没清理,占用太大空间

1.查看binlog过期时间

show variables like 'expire_logs_days';

image

expire_logs_days=0:
这里的值如果为0,表示所有binlog日志永久都不会失效,不会自动删除;
这里的值如果为30,表示只保留最近30天。

2. 修改binlog过期时间

  1. 永久生效(重启后即生效) 修改配置文件my.cnf文件: vim /etc/my.cnf
在[mysqld]标签内增加如下内容
expire_logs_days=30
max_binlog_size=1024M

修改保存后,以下3种情况才生效
1)当binlog大小超过max_binlog_size
2)手动执行flush logs
3)重新启动

为了使之生效,需要执行flush logs。
mysql> flush logs;
Query OK, 0 rows affected, 64 warnings (0.16 sec

3.手工清除历史binlog

如果binlog非常多,推荐使用purge命令予清除历史文件:image
比如将mysql-bin.009560之前的binlog清掉:

mysql>purge binary logs to 'mysql-bin.009560';

或者指定时间之前的binlog清掉:

mysql>purge binary logs before '2022-01-01 23:59:59';

本文转载自: https://blog.csdn.net/wang6733284/article/details/126837136
版权归原作者 硅谷工具人 所有, 如有侵权,请联系我们删除。

“清理MySQL中的binlog”的评论:

还没有评论