mysql8 设置binlog过期时间

mysql8 设置binlog过期时间

mysql8中 使用binlog_expire_logs_seconds 设置日志过期时间,废弃参数:expire_logs_days

mysql> show variables like '%expire%';
+--------------------------------+---------+
| Variable_name                  | Value   |
+--------------------------------+---------+
| binlog_expire_logs_seconds     | 2592000 |
| disconnect_on_expired_password | ON      |
| expire_logs_days               | 0       |
+--------------------------------+---------+

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)

mysql8 默认设置的binlog过期时间是30天;
如下设置过期日期为7天:

mysql> set global binlog_expire_logs_seconds=604800;

查看binlog

查看binary logs名称列表

mysql> show binary logs;

查看binlog内容

mysql> show binlog events;

手工刷新日志

mysql> show binary logs;
+----------------------+-----------+-----------+
| Log_name             | File_size | Encrypted |
+----------------------+-----------+-----------+
| HURYER-PC-bin.000028 |       155 | No        |
+----------------------+-----------+-----------+
1 rows in set (0.00 sec)

mysql> flush  logs;
Query OK, 0 rows affected (0.03 sec)

mysql> show binary logs;
+----------------------+-----------+-----------+
| Log_name             | File_size | Encrypted |
+----------------------+-----------+-----------+
| HURYER-PC-bin.000028 |       206 | No        |
| HURYER-PC-bin.000029 |       155 | No        |
+----------------------+-----------+-----------+
2 rows in set (0.00 sec)

清理日志

mysql> purge binary logs to 'HURYER-PC-bin.000029';
Query OK, 0 rows affected (0.01 sec)

mysql> show binary logs;
+----------------------+-----------+-----------+
| Log_name             | File_size | Encrypted |
+----------------------+-----------+-----------+
| HURYER-PC-bin.000029 |       155 | No        |
+----------------------+-----------+-----------+
1 row in set (0.00 sec)
mysql> purge binary logs before '2020-03-08';
Query OK, 0 rows affected (0.02 sec)

你可能感兴趣的:(mysql,mysql8,binlog,过期时间,清除日志)