zabbix服务器上MYSQL占空间,发现binlog每个大小1G多:
删除Binlog:
[root@zabbix5 data]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 40075
Server version: 8.0.21 MySQL Community Server - GPL
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show master logs;
+---------------+------------+-----------+
| Log_name | File_size | Encrypted |
+---------------+------------+-----------+
| binlog.000158 | 1073742177 | No |
| binlog.000159 | 1073742069 | No |
| binlog.000160 | 1073743376 | No |
| binlog.000161 | 1073742669 | No |
| binlog.000162 | 1073742083 | No |
| binlog.000163 | 1073743613 | No |
| binlog.000164 | 160199812 | No |
| binlog.000165 | 947050252 | No |
+---------------+------------+-----------+
8 rows in set (0.18 sec)
mysql> PURGE MASTER LOGS BEFORE DATE_SUB(CURRENT_DATE, INTERVAL 10 DAY);
Query OK, 0 rows affected (0.04 sec)
mysql> show master logs;
+---------------+------------+-----------+
| Log_name | File_size | Encrypted |
+---------------+------------+-----------+
| binlog.000163 | 1073743613 | No |
| binlog.000164 | 160199812 | No |
| binlog.000165 | 947079829 | No |
+---------------+------------+-----------+
3 rows in set (0.00 sec)
mysql> reset master;
Query OK, 0 rows affected (0.09 sec)
mysql> exit
设置自动清理:
# 只保留7天内的 binlog 文件
mysql> set global binlog_expire_logs_seconds=60*60*168;