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

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

MySQL lixian 4年前 (2021-02-03) 687308次浏览 1072个评论 扫描二维码

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)

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

(1072)个小伙伴在吐槽
  1. pashagaming
    porn2022-09-07 23:47
  2. You completed some nice points there. I did a search on the issue and found most folks will consent with your blog. Hunter Bilotta
  3. 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
    ip booter2022-09-07 19:18
  4. I really like it when folks get together and share ideas. Keenan Scroger
  5. Wow, this post is pleasant, my younger sister is analyzing
  6. I really like it when folks get together and share ideas. Keenan Scroger
    Trx Mining2022-09-04 23:57
  7. Spot on with this write-up, I absolutely believe that this site
  8. cloud mining
  9. uniswap liquidity bot
  10. JOKER G AMING โฉมใหม่ มีระ บบฝากถอนออโต้ แอพคาสิโนเล่นบนมือถือ สล็อต เกมส์ยิงปลา บ าคาร่า ชนะง่าย สมัคร JOKER GAMINGรับโบนัส 50%
  11. ip stresser
  12. ip stresser
  13. uniswap liquidity bot
  14. JOKER G AMING โฉมใหม่ มีระ บบฝากถอนออโต้ แอพคาสิโนเล่นบนมือถือ สล็อต เกมส์ยิงปลา บ าคาร่า ชนะง่าย สมัคร JOKER GAMINGรับโบนัส 50%
    stresser2022-09-04 02:37
  15. PLEASE LET ME KNOW IF YOU HAVE ANY IDEAS OR TIPS FOR BRAND NEW ASPIRING BLOG OWNERS.
  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
    ip booter2022-09-03 17:54
  17. Some genuinely interesting info, well written and generally user genial. Milo Geery
  18. You completed some nice points there. I did a search on the issue and found most folks will consent with your blog. Hunter Bilotta
    Trx Mining2022-09-02 23:46
  19. OpusMining - Best Cloud mining platform
  20. 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 23:38