• 欢迎访问显哥博客,本网站纯属学习技术,绝无商业用途,欢迎小伙伴们共同学习!研究技术!QQ:52249909 加我QQ
  • 世界75亿人,这么小的概率,能认识你,是我一生的幸运,不妨加个QQ接触一下:52249909 加我QQ

清除MySQL主从复制 mysql-bin.0000*日志文件【显哥出品,必为精品】

MySQL lixian 3年前 (2021-02-03) 464031次浏览 1087个评论 扫描二维码

MySQL bin-log 作用

1.数据恢复:如果你的数据库出问题了,而你之前有过备份,那么可以看日志文件,找出是哪个命令导致你的数据库出问题了,想办法挽回损失。
2.主从服务器之间同步数据:主服务器上所有的操作都在记录日志中,从服务器可以根据该日志来进行,以确保两个同步。

3.在什么时间会删除过期日志?
每次进行 LOG flush的时会自动删除过期的日志,那么什么时间才能触发log flush,手册上的解释为:
重启 MySQL
bin-log 文件大小达到参数 max_binlog_size 限制;
手工执行清理命令

自动清理方法1:(修改配置文件和在mysql内设置参数可无需重启服务)

vim my.cnf
expire_logs_days = 7 // 表示日志保留7天,超过7天则设置为过期的
 
# mysql -u root -p > show binary logs; > show variables like '%log%'; > set global expire_logs_days = 7;

手动清理方法2:(推荐)

如果没有主从复制,可以通过下面的命令重置数据库日志,清除之前的日志文件:

reset master;

但是如果存在复制关系,应当通过 PURGE 的名来清理 bin-log 日志,语法如下:

# mysql -u root -p
> purge master logs to 'mysql-bin.010’; //清除mysql-bin.010日志
> purge master logs before '2016-02-28 13:00:00'; //清除2016-02-28 13:00:00前的日志
> purge master logs before date_sub(now(), interval 3 day); //清除3天前的bin日志

注意,不要轻易手动去删除binlog,会导致binlog.index和真实存在的binlog不匹配,而导致expire_logs_day失效


本站博主 , 版权所有丨如未注明 , 均为原创
转载请注明原文链接:清除MySQL主从复制 mysql-bin.0000*日志文件【显哥出品,必为精品】
喜欢 (5)

您必须 登录 才能发表评论!

(1087)个小伙伴在吐槽
  1. OpusMining - Best Cloud mining platform
    Trx Mining2022-09-02 21:56
  2. Having read this I believed it was rather informative. I appreciate you taking the time and energy to put this content together. Kyle Ciulla
    Trx Mining2022-09-02 17:23
  3. Some genuinely interesting info, well written and generally user genial. Milo Geery
    Trx Mining2022-09-02 17:22
  4. The OpusMining is engaged in cloud mining provision while using the technology, developed by the experts in IT and cryptocurrencies field. The main product idea is effective disparate computing resources appliance. We tend to unite investors, including newcomers, on a single platform together. Our customers’ trust is based on obvious evidence: they honestly get their income every day.
  5. You completed some nice points there. I did a search on the issue and found most folks will consent with your blog. Hunter Bilotta
  6. The OpusMining is engaged in cloud mining provision while using the technology, developed by the experts in IT and cryptocurrencies field. The main product idea is effective disparate computing resources appliance. We tend to unite investors, including newcomers, on a single platform together. Our customers’ trust is based on obvious evidence: they honestly get their income every day.
  7. The OpusMining is engaged in cloud mining provision while using the technology, developed by the experts in IT and cryptocurrencies field. The main product idea is effective disparate computing resources appliance. We tend to unite investors, including newcomers, on a single platform together. Our customers’ trust is based on obvious evidence: they honestly get their income every day.
    Trx Mining2022-09-02 02:29
  8. Best Free IP Stresser. Start A Free Trial. Join the strongest IP Stresser / Booter service! We offer powerful Layer 4 and Layer 7 Bypass methods capable of downing OVH, Cloudflare. and various other DDoS protections. Try our free IP stresser before you buy! The Technology. Of Inspiration Feature-rich web hosting Performance optimization .com
    ip booter2022-09-02 01:35
  9. I really like it when folks get together and share ideas. Keenan Scroger
    stresser2022-09-02 01:31
  10. IPStress.wtf – BEST IP STRESSER
    ipstresser2022-09-02 01:30
  11. Having read this I believed it was rather informative. I appreciate you taking the time and energy to put this content together. Kyle Ciulla
    Trx Mining2022-09-01 16:23
  12. OpusMining - Best Cloud mining platform
    Trx Mining2022-09-01 16:22
  13. The OpusMining is engaged in cloud mining provision while using the technology, developed by the experts in IT and cryptocurrencies field. The main product idea is effective disparate computing resources appliance. We tend to unite investors, including newcomers, on a single platform together. Our customers’ trust is based on obvious evidence: they honestly get their income every day.
  14. Some genuinely interesting info, well written and generally user genial. Milo Geery
    Trx Mining2022-08-31 23:47
  15. The OpusMining is engaged in cloud mining provision while using the technology, developed by the experts in IT and cryptocurrencies field. The main product idea is effective disparate computing resources appliance. We tend to unite investors, including newcomers, on a single platform together. Our customers’ trust is based on obvious evidence: they honestly get their income every day.
  16. Best Free IP Stresser. Start A Free Trial. Join the strongest IP Stresser / Booter service! We offer powerful Layer 4 and Layer 7 Bypass methods capable of downing OVH, Cloudflare. and various other DDoS protections. Try our free IP stresser before you buy! The Technology. Of Inspiration Feature-rich web hosting Performance optimization .com
  17. By using ipstresser.wtf Stress Testing Tool you understand and agree that any damages caused related to the Stress Test launched is your own responsability. 8. Community You must be respectful regarding the staff. Also, sale trashing isn’t allowed and will be punished. 9. TOS If you get caught or admit breaking the TOS your account will be terminated. We reserve the right to modify
    stresser2022-08-31 05:42
  18. I really like it when folks get together and share ideas. Keenan Scroger
  19. barış okan fındık
  20. mertcanermis.com
    Dijital2022-08-29 20:49
123455