开发者

如何清理MySQL中的binlog问题

目http://www.devze.com录
  • 清理mysql中的binlog
    • 1.查看binlog过期时间
    • 2. 修改binlog过期时间
    • 3.手工清除历史binlog
  • 总结

    清理MySQL中的binlog

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

    1.查看binlog过期时间

    show variables like 'expire_logs_days';

    如何清理MySQL中的binlog问题

    expire_logs_days=0:

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

    2. 修改binlog过期时间

    永久生效(重启后即生效)

    修改配置文件mandroidy.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 sehttp://www.devze.comc

    3.手工清除历史binlog

    如果binlog非常多,推荐使用purge命令予清除历史文件:

    如何清理MySQL中的binlog问题

    比如将mysql-bin.009560之前的binlog清掉:

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

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

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

    总结

    以上为个人经验,希望能给大家一个参考,也希望大家多多支持编程客栈(www.devze.com)。

    0

    上一篇:

    下一篇:

    精彩评论

    暂无评论...
    验证码 换一张
    取 消

    最新数据库

    数据库排行榜