在线修改
mysql> show variables like '%expire%';
+--------------------------------+---------+
| Variable_name | Value |
+--------------------------------+---------+
| binlog_expire_logs_auto_purge | ON |
| binlog_expire_logs_seconds | 2592000 |
| disconnect_on_expired_password | ON |
| expire_logs_days | 0 |
+--------------------------------+---------+
4 rows in set (0.02 sec)
mysql> set global expire_logs_days=1;
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=86400;
Query OK, 0 rows affected (0.00 sec)
mysql> show variables like '%expire%';
+--------------------------------+-------+
| Variable_name | Value |
+--------------------------------+-------+
| binlog_expire_logs_auto_purge | ON |
| binlog_expire_logs_seconds | 86400 |
| disconnect_on_expired_password | ON |
| expire_logs_days | 0 |
+--------------------------------+-------+
4 rows in set (0.02 sec)
mysql> flush logs;
Query OK, 0 rows affected (2.77 sec)
mysql> show binary logs;
+---------------+------------+-----------+
| Log_name | File_size | Encrypted |
+---------------+------------+-----------+
| binlog.000034 | 1150850956 | No |
| binlog.000035 | 1073745962 | No |
| binlog.000036 | 1073765209 | No |
| binlog.000037 | 1036964608 | No |
| binlog.000038 | 1105127830 | No |
| binlog.000039 | 1136391108 | No |
| binlog.000040 | 1112828317 | No |
| binlog.000041 | 1109221590 | No |
| binlog.000042 | 165709537 | No |
| binlog.000043 | 955575 | No |
+---------------+------------+-----------+
10 rows in set (0.00 sec)
mysql> \q
命令解析:
查看binlog设置
mysql> show variables like '%expire%';
注:mysql8.0以下版本binlog保存时效 以天为单位,参数为expire_logs_days,默认0为永不过期。mysql8.0以上版本binlog保存时效 以秒为单位,参数为binlog_expire_logs_seconds,默认的binlog过期时间为2592000秒,也就是30天。
设置过期日期为1天(1d=86400s)
mysql> set global binlog_expire_logs_seconds=86400;
注:mysql8.0之后弃用了expire_logs_days=1这种形式,上面在线修改中特意 示范 错误形式,不需要模仿,知道就可!
配置成功后,手动刷新清理过期日志
mysql> flush logs;
查看现有的binglog
mysql> show binary logs;标签:binlog,set,logs,No,expire,mysql8.0,mysql,日志 From: https://blog.51cto.com/u_15932009/5992968