当前位置:网站首页>mysql binlog的清理
mysql binlog的清理
2022-07-01 22:32:00 【undo_try】
Linux磁盘空间占满解决方法
查询整体磁盘使用情况命令
df -h
* / df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 3.8G 0 3.8G 0% /dev
tmpfs 3.8G 0 3.8G 0% /dev/shm
tmpfs 3.8G 393M 3.5G 11% /run
tmpfs 3.8G 0 3.8G 0% /sys/fs/cgroup
/dev/vda1 40G 30G 7.2G 81% /
tmpfs 777M 0 777M 0% /run/user/1000
查询某个目录下各文件夹或文件大小
sudo du -sh *
* / sudo du -sh *
0 bin
211M boot
...
2.2G usr
26G var
然后进入/var目录下,继续使用该命令查看,发现是binlog过多导致,需要删除binlog日志。
清理mysql binlog
mysql的binlog必不可少,但是不清理的话,小云盘经受不住每天频繁的插入删除。所以binlog日志还需要删除。
mysql> show variables like ‘%expire%’;

查询上述参数后发现在MySQL 8.0.12版本中默认开启binlog日志并设置为binlog_format=row,binlog失效日期参数为 binlog_expire_logs_seconds,默认30天过期。
注释:
在MySQL8.0 版本中新增参数binlog_expire_logs_seconds,可以精确到秒,而此前版本中expire_logs_days的单位为天,最小值为1,在MySQL8.0 GA中此参数标记为deprecated 。
在MySQL 8.0 GA版本默认使用binlog_expire_logs_seconds,时间为2592000秒,30天。
- 若在MySQL启动时
inlog_expire_logs_seconds和expire_logs_days都没设置值,则使用默认值的binlog_expire_logs_seconds值,即30天; - 若在MySQL启动时
binlog_expire_logs_seconds或者expire_logs_days其中一个设置为非0值则非0值的参数作为binlog日志失效期; - 若在启动时
binlog_expire_logs_seconds和expire_logs_days参数都设置为非0值则使用binlog_expire_logs_seconds值,expire_logs_days值则失效并对其发出告警信息。
若要关闭自动清除binlog文件的功能则需要显示指定binlog_expire_logs_seconds=0 并且不设置expire_logs_days的值。
为了兼容早期版本若显示指定了expire_logs_days =0而没有指定binlog_expire_logs_seconds的值,此时自动清理binlog日志则是 禁用 的,并且此时binlog_expire_logs_seconds的默认值不适用。
手动删除日志
手动清理当然指的不是 rm -rf ** ,这样可能会导致 binlog.index 错乱。
mysql -uroot -p # 登陆mysql
show binary logs; # 查看日志文件
show master status; # 查看正在使用的日志文件:binlog.000015
purge binary logs to 'binlog.000015'; # 删除binlog.000015文件以外的日志文件
设置过期时间
设置过期48小时
mysql> set global binlog_expire_logs_seconds=60*60*48;
mysql> flush logs; # 刷一下log使上面的设置生效,否则不生效。注意:此配置重启mysql后失效。
边栏推荐
- Cisco test -- the concept and configuration test of routing
- Understanding threads
- 赵福全:短期解决保供,长期要打造安全、高效有韧性的供应链
- 想请教一下,证券开户选择哪个证券比较好?手机开户是安全么?
- Unable to climb hill sort, directly insert sort
- 正则系列之量词(Quantifiers)
- [QT widget] encapsulates a simple thread management class
- URL 介绍
- Daily question brushing record (10)
- The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received
猜你喜欢

玻璃马赛克

Programming English vocabulary notebook

Explain JMM in detail

Vsphere+ and vsan+ are coming! VMware hybrid cloud focus: native, fast migration, mixed load

rviz打开后如何显示实时2D地图
![[kotlin third party] coil koltin collaboration picture loading library coil glide like picture loading third party](/img/ad/dcb993c3e1e79d2c3663f031dfd1b3.png)
[kotlin third party] coil koltin collaboration picture loading library coil glide like picture loading third party
![Compare the version number [double pointer to intercept the string you want]](/img/19/4f858ffdc1281d6b8b18a996467f10.png)
Compare the version number [double pointer to intercept the string you want]

微信个人小商店一键开通助手小程序开发

CKS CKA CKAD 将终端更改为远程桌面

会声会影2022智能、快速、简单的视频剪辑软件
随机推荐
[image segmentation] 2021 segformer neurips
Convergence and disposal suggestions of some Internet exposure surfaces
The principle, testing and Countermeasures of malicious software reverse closing EDR
MySQL -- convert rownum in Oracle to MySQL
El input text field word limit, beyond which the display turns red and input is prohibited
关于游戏性能优化的一些感想
测试人进阶技能:单元测试报告应用指南
Programming English vocabulary notebook
若干互联网暴露面的收敛及处置建议
玻璃马赛克
赵福全:短期解决保供,长期要打造安全、高效有韧性的供应链
Redis~02 cache: how to ensure data consistency in MySQL and redis when updating data?
shell 流程控制
Turn -- the underlying debugging principle of GDB is so simple
工作中非常重要的测试策略,你大概没注意过吧
“信任机器”为发展赋能
Demo program implementation of QT version Huarui camera
使用 EMQX Cloud 实现物联网设备一机一密验证
转--深入LUA脚本语言,让你彻底明白调试原理
使用3DMax制作一个象棋棋子