查看当前日志保存天数:
- mysql> show variables like '%expire_logs_days%';
- +------------------+-------+
- | Variable_name | Value |
- +------------------+-------+
- | expire_logs_days | 0 |
- +------------------+-------+
- 1 row in set (0.08 sec)
复制代码 默认是0,也就是logs不逾期。
也可以使用 show variables like '%expire%' 查看是否有开启日志到期自动删除
- mysql> show variables like '%expire%';
- +--------------------------------+--------+
- | Variable_name | Value |
- +--------------------------------+--------+
- | binlog_expire_logs_auto_purge | ON |
- | binlog_expire_logs_seconds | 432000 |
- | disconnect_on_expired_password | ON |
- | expire_logs_days | 0 |
- +--------------------------------+--------+
- 4 rows in set (0.00 sec)
复制代码 设置BINLOG到期时间
暂时见效,无需重起mysql
如果数据库此时不便重启,可以设置全局的参数,使他暂时见效:
mysql> set global expire_logs_days=5;
设置了只保存5天BINLOG, 下次重启mysql这个参数默认会失败。
如果上面指令报错,则改为set global binlog_expire_logs_seconds=432000
- 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=432000;Query OK, 0 rows affected (0.00 sec)mysql> mysql> show variables like '%expire%';
- +--------------------------------+--------+
- | Variable_name | Value |
- +--------------------------------+--------+
- | binlog_expire_logs_auto_purge | ON |
- | binlog_expire_logs_seconds | 432000 |
- | disconnect_on_expired_password | ON |
- | expire_logs_days | 0 |
- +--------------------------------+--------+
- 4 rows in set (0.00 sec)
复制代码 写入设置文件,mysql重启依旧见效
如果要永世见效,需要在my.cnf中设置
vi /etc/my.cnf
追加内容:
binlog_expire_logs_seconds=432000
手动删除BINLOG
也可以先手动删除BINLOG (purge binary logs)
删除指定的日志
mysql> PURGE {MASTER | BINARY} LOGS TO 'log_name'
例:删除binlog.1000
mysql> PURGE MASTER LOGS TO 'binlog.1000';
或删除指定日期之前的日志索引中的全部二进制日志。
mysql> PURGE {MASTER | BINARY} LOGS BEFORE 'date'
例:删除2023-06-03 12:00:00前的文件
mysql> PURGE MASTER LOGS BEFORE '2023-06-03 12:00:00';
例:删除3天前的日志
mysql> PURGE MASTER LOGS BEFORE DATE_SUB( NOW( ), INTERVAL 3 DAY);
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |