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

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

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

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)

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

(1091)个小伙伴在吐槽
  1. antalya web tasarım
  2. I like this site. Cheers!
  3. Deseler ile hayata bak sende, en iyi icerikler burada.
    Deseler2023-06-09 20:08
  4. thanks a lot
  5. Türkiyenin bir numaralı haber platformunu hemen inceleyin.
  6. Sizler de en uygun fiyatlar ile yüksek kaliteli vds server kiralama hizmetine sahip olun sitelerinizi zirveye çıkartın.
    vds2023-06-09 05:38
  7. Krem tanıtımları
    kremler2023-06-08 20:54
  8. This is awesome. thanks for post!
  9. Оборудование и инструменты от Технопрома доступны на technoprom.kz
    匿名2023-06-07 04:58
  10. Hey guys, I'm trying to sell my house fast in Colorado and I was wondering if anyone had any tips or suggestions on how to do it quickly and efficiently? I've already tried listing it on some popular real estate websites, but I haven't had much luck yet. I'm thinking about working with a local real estate agent, but I'm not sure if that's the best option for me. I'm open to any and all suggestions, so please feel free to share your ideas. Thanks in advance!
    匿名2023-06-06 04:11
  11. quality and beautiful content
  12. nice content thanks
  13. it is a great article. thank you very much.
  14. great article. thank you very much. very helpful.
  15. very helpful. thank you very much.
  16. Tack så mycket för den utmärkta artikeln. Jag ska definitivt rekommendera den till mina vänner. Tack igen.
    dollar sek2023-06-04 16:02
  17. If you're in need of a new boiler, our skilled technicians can handle the installation process with precision and professionalism. [url=https://www.myconcertarchive.com/en/user_home?id=78393] Underfloor heating repairs!..[/url]
    匿名2023-06-04 11:11
  18. wiat Karpia - portal dla karpiarzy [url=https://swiatkarpia.com/users/ryder_carter_97]More info!..[/url]
    匿名2023-06-04 10:46
  19. As certified Corgi plumbers, we adhere to strict safety standards and deliver high-quality plumbing services. [url=https://www.in-pocasi.cz/uzivatele/isabel_johnson82-115811/] Drainage & waste pipe>>>[/url]
    匿名2023-06-04 07:56
  20. Our expert team can repair and replace radiators to ensure efficient heating throughout your home or office. [url=http://www.healthsafety.com/user/178221/] Blocked manholes>>>[/url]
    匿名2023-06-04 06:37