mysql 8 设置binlog过期时间

复制代码
mysql> select version();
+-----------+
| version() |
+-----------+
| 8.0.22    |
+-----------+
1 row in set (0.01 sec)
mysql> show variables like '%expire%';
+--------------------------------+---------+
| Variable_name                  | Value   |
+--------------------------------+---------+
| binlog_expire_logs_seconds     | 2592000 |
| disconnect_on_expired_password | ON      |
| expire_logs_days               | 0       |
+--------------------------------+---------+
 
默认情况下binglog的失效日期为30天,设置为0则表示永不失效。
以前的参数expire_logs_days废弃不用了。
mysql> set global expire_logs_days=7;
ERROR 3683 (HY000): The option expire_logs_days and binlog_expire_logs_seconds cannot be used together. 
Please use binlog_expire_logs_seconds to set the expire time (expire_logs_days is deprecated)

mysql> set global binlog_expire_logs_seconds=3*24*60*60;
Query OK, 0 rows affected (0.00 sec)
 
mysql> flush logs;
Query OK, 0 rows affected (0.06 sec)

# 配置文件设置binlog过期时间
expire_logs_days=1 mysql
> show binary logs; 说明: 在MySQL 8.0之前 使用的参数expire_logs_days 只能设置到天,在新版本可以精确到秒 。 清理日期之前的binlog日志 mysql> purge binary logs before '2021-22-20 22:00:00'; Query OK, 0 rows affected, 1 warning (0.01 sec) mysql> show binary logs;
复制代码

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

mysql> purge binary logs to 'binlog.005237';
Query OK, 0 rows affected, 933 warnings (0.43 sec)

清空表

truncate table

 

posted @   不会跳舞的胖子  阅读(1266)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~
点击右上角即可分享
微信分享提示