清除MySQL的binlog

ubuntu@pzkxj:~df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            7.7G     0  7.7G   0% /dev
tmpfs           1.6G  1.4M  1.6G   1% /run
/dev/vda2       178G  161G  9.1G  95% /
tmpfs           7.7G   24K  7.7G   1% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           7.7G     0  7.7G   0% /sys/fs/cgroup
/dev/vdb        196G  147G   40G  79% /home/ubuntu/oh_home_new
tmpfs           1.6G   48K  1.6G   1% /run/user/1000
ubuntu@pzkxj:~ docker exec -it mysql-mid mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1132
Server version: 8.0.45 MySQL Community Server - GPL

Copyright (c) 2000, 2026, Oracle and/or its affiliates.

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>
mysql> PURGE BINARY LOGS BEFORE NOW() - INTERVAL 1 DAY;
Query OK, 0 rows affected (0.08 sec)

mysql> SHOW BINARY LOGS;
+---------------+------------+-----------+
| Log_name      | File_size  | Encrypted |
+---------------+------------+-----------+
| binlog.000043 | 1074243608 | No        |
| binlog.000044 | 1074953561 | No        |
| binlog.000045 | 1074228211 | No        |
| binlog.000046 | 1073742657 | No        |
| binlog.000047 | 1074293932 | No        |
| binlog.000048 | 1074058862 | No        |
| binlog.000049 | 1075129056 | No        |
| binlog.000050 | 8562452881 | No        |
| binlog.000051 |  170348497 | No        |
| binlog.000052 | 1075075806 | No        |
| binlog.000053 | 1074075977 | No        |
| binlog.000054 | 1074797176 | No        |
| binlog.000055 | 1074730552 | No        |
| binlog.000056 | 1073742280 | No        |
| binlog.000057 | 1074626601 | No        |
| binlog.000058 | 1075252954 | No        |
| binlog.000059 | 1074548328 | No        |
| binlog.000060 | 1073745787 | No        |
| binlog.000061 | 1074594475 | No        |
| binlog.000062 | 1073744666 | No        |
| binlog.000063 | 1073838945 | No        |
| binlog.000064 | 1074231367 | No        |
| binlog.000065 | 1073742096 | No        |
| binlog.000066 | 1074661101 | No        |
| binlog.000067 | 1074971025 | No        |
| binlog.000068 | 1074275023 | No        |
| binlog.000069 | 1073742686 | No        |
| binlog.000070 | 1073741956 | No        |
| binlog.000071 | 1074101497 | No        |
| binlog.000072 |  363448582 | No        |
+---------------+------------+-----------+
30 rows in set (0.00 sec)

mysql> PURGE BINARY LOGS BEFORE NOW() - INTERVAL 1 HOUR;
Query OK, 0 rows affected (1.01 sec)

mysql> SHOW BINARY LOGS;
+---------------+------------+-----------+
| Log_name      | File_size  | Encrypted |
+---------------+------------+-----------+
| binlog.000071 | 1074101497 | No        |
| binlog.000072 |  372853013 | No        |
+---------------+------------+-----------+
2 rows in set (0.01 sec)

mysql> exit
Bye
ubuntu@pzkxj:~df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            7.7G     0  7.7G   0% /dev
tmpfs           1.6G  1.4M  1.6G   1% /run
/dev/vda2       178G  106G   65G  63% /
tmpfs           7.7G   24K  7.7G   1% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           7.7G     0  7.7G   0% /sys/fs/cgroup
/dev/vdb        196G  147G   40G  79% /home/ubuntu/oh_home_new
tmpfs           1.6G   48K  1.6G   1% /run/user/1000
ubuntu@pzkxj:~ docker exec -it mysql-mid mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1135
Server version: 8.0.45 MySQL Community Server - GPL

Copyright (c) 2000, 2026, Oracle and/or its affiliates.

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> SET GLOBAL binlog_expire_logs_seconds = 3600;
Query OK, 0 rows affected (0.00 sec)

mysql> exit

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注