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

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

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

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)

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

(1083)个小伙伴在吐槽
  1. mertcanermis.com
    Katman2022-08-29 02:43
  2. hdfilmkeyfi.net sitemize giriş yapın ve hd film keyfi yaşayın.
  3. hdfilmkeyfi.net sitemize giriş yapın ve hd film keyfi yaşayın.
  4. hdfilmkeyfi.net sitemize giriş yapın ve hd film keyfi yaşayın.
  5. hdfilmkeyfi.net ile film izlemeye doyamayacaksınız
  6. Appreciate you sharing, great blog post. Much thanks again. Awesome. Lester Binford
    bahis oyna2022-08-13 20:20
  7. At this moment I am redady to doo my breakfast, afterward having my breakfast coming yet again to read further news. Bertram Natwick
    porno2022-08-13 12:23
  8. Really appreciate you sharing this blog. Thanks Again. Cool. Pasquale Redmer
    porno2022-08-11 02:30
  9. Way cool! Some extremely valid points! I appreciate you penning this post and the rest of the website is extremely good. Scott Axson
    buy viagra2022-08-10 09:26
  10. There is certainly a lot to find out about this topic. I really like all of the points you made. Stanley Kolk
    porno2022-08-08 15:02
  11. When some one searches for his essential thing, thus he/she desires to be available that in detail, thus that thing is maintained over here. Everette Moranda
    bedava2022-07-20 13:37
  12. Perfect work you have done, this internet site is really cool with good information. Rolf Bushong
    porno2022-07-19 17:43
  13. A big thank you for publishing such a valuable article on this topic. I hope to find here much more from you, in the coming weeks. Merle Tellefsen
    porno2022-07-18 15:08
  14. Ahaa, its pleasant discussion on the topic of this post at this place at this web site, I have read all that, so at this time me also commenting here. Clay Kyseth
    sikis izle2022-07-11 13:13
  15. I think you have remarked some very interesting details, regards for the post. Hershel Meurin
    bahis oyna2022-07-09 13:33
  16. I do agree with all the concepts you have offered in your post. They are really convincing and will definitely work. Thank you for the post.
  17. Your style is so unique compared to other people I have read stuff from. I appreciate you for posting when you've got the opportunity. Guess I will just bookmark this web site.
  18. veterinerlik, veteriner maaşları, veteriner nasıl olunur
  19. Hey, thanks for the blog article. Really thank you! Really Cool. Matt Voorhes
  20. This was the best content we could see and it fixed the problem.
    xxx2022-06-23 06:23
12355