在配置了MySQL主从复制的MySQL环境中,MySQL会生成大量二进制文件用于从节点数据同步;大量的二进制文件如果不进行及时清理的话会占用大量的磁盘空间,以下演示了清理二进制文件的实例:[root@mysql1 data]# pwd
/usr/local/mysql/data
[root@mysql1 data]# ls
eduportal mysql1.pid mysql-bin.000006 mysql-bin.000014 mysql-bin.000022 mysql-bin.000030 mysql-bin.000038
ibdata1 mysql1-slow.log mysql-bin.000007 mysql-bin.000015 mysql-bin.000023 mysql-bin.000031 mysql-bin.index
ib_logfile0 mysql1-slow.log.old mysql-bin.000008 mysql-bin.000016 mysql-bin.000024 mysql-bin.000032 performance_schema
ib_logfile1 mysql-bin.000001 mysql-bin.000009 mysql-bin.000017 mysql-bin.000025 mysql-bin.000033 portal
ib_logfile2 mysql-bin.000002 mysql-bin.000010 mysql-bin.000018 mysql-bin.000026 mysql-bin.000034 test
mysql mysql-bin.000003 mysql-bin.000011 mysql-bin.000019 mysql-bin.000027 mysql-bin.000035
mysql1.err mysql-bin.000004 mysql-bin.000012 mysql-bin.000020 mysql-bin.000028 mysql-bin.000036
mysql1.err.old mysql-bin.000005 mysql-bin.000013 mysql-bin.000021 mysql-bin.000029 mysql-bin.000037
[root@mysql1 data]# ls -lrth
鎬昏 31G
drwx------ 2 mysql mysql 4.0K 09-22 18:04 performance_schema
drwx------ 2 mysql mysql 4.0K 09-22 18:04 mysql
-rw-rw---- 1 mysql mysql 107 09-22 18:06 mysql-bin.000001
-rw-rw---- 1 mysql mysql 126 09-22 18:11 mysql-bin.000002
-rw-rw---- 1 mysql mysql 1.2K 09-22 18:47 mysql-bin.000003
drwxr-x--- 2 mysql mysql 4.0K 09-22 18:54 test
-rw-rw---- 1 mysql mysql 512 09-23 09:48 mysql-bin.000004
-rw-rw---- 1 mysql mysql 1.1G 09-23 19:29 mysql-bin.000005
-rw-rw---- 1 mysql mysql 1.1G 09-23 19:32 mysql-bin.000006
-rw-rw---- 1 mysql mysql 1.1G 09-23 19:39 mysql-bin.000007
-rw-rw---- 1 mysql mysql 1.1G 09-23 23:22 mysql-bin.000008
-rw-rw---- 1 mysql mysql 1.1G 09-23 23:25 mysql-bin.000009
-rw-rw---- 1 mysql mysql 1.1G 09-23 23:29 mysql-bin.000010
-rw-rw---- 1 mysql mysql 1.1G 09-23 23:36 mysql-bin.000011
-rw-rw---- 1 mysql mysql 1.1G 09-30 08:13 mysql-bin.000012
-rw-rw---- 1 mysql mysql 1.1G 10-13 09:03 mysql-bin.000013
-rw-rw---- 1 mysql mysql 1.1G 10-22 15:47 mysql-bin.000014
-rw-rw---- 1 mysql mysql 80M 10-24 00:08 mysql1-slow.log.old
-rw-rw---- 1 mysql mysql 246M 10-24 01:50 mysql-bin.000015
-rw-r----- 1 mysql root 391M 10-24 01:52 mysql1.err.old
-rw-rw---- 1 mysql mysql 126 10-24 02:29 mysql-bin.000016
-rw-rw---- 1 mysql mysql 11K 10-24 02:56 mysql-bin.000017
-rw-rw---- 1 mysql mysql 1.0G 10-24 02:57 ib_logfile2
-rw-rw---- 1 mysql mysql 21K 10-24 03:09 mysql-bin.000018
-rw-rw---- 1 mysql mysql 126 10-24 03:10 mysql-bin.000019
-rw-rw---- 1 mysql mysql 41K 10-24 03:34 mysql-bin.000020
-rw-rw---- 1 mysql mysql 25K 10-24 03:40 mysql-bin.000021
-rw-rw---- 1 mysql mysql 1.1G 11-02 19:03 mysql-bin.000022
-rw-rw---- 1 mysql mysql 1.1G 11-03 20:02 mysql-bin.000023
-rw-rw---- 1 mysql mysql 1.1G 11-03 20:08 mysql-bin.000024
-rw-rw---- 1 mysql mysql 1.3G 11-04 09:38 mysql-bin.000025
-rw-rw---- 1 mysql mysql 1.1G 11-13 16:14 mysql-bin.000026
drwx------ 2 mysql mysql 20K 11-18 14:51 eduportal
-rw-rw---- 1 mysql mysql 1.1G 11-18 16:55 mysql-bin.000027
drwx------ 2 mysql mysql 12K 11-19 14:07 portal
-rw-rw---- 1 mysql mysql 1.1G 11-19 14:58 mysql-bin.000028
-rw-rw---- 1 mysql mysql 1.1G 11-19 17:52 mysql-bin.000029
-rw-rw---- 1 mysql mysql 1.1G 11-19 19:50 mysql-bin.000030
-rw-rw---- 1 mysql mysql 1.1G 11-19 21:38 mysql-bin.000031
-rw-rw---- 1 mysql mysql 867M 11-20 05:44 mysql-bin.000032
-rw-rw---- 1 mysql mysql 1.7M 11-20 05:48 mysql-bin.000033
-rw-rw---- 1 mysql mysql 5 11-20 05:48 mysql1.pid
-rw-r----- 1 mysql root 22K 11-20 05:48 mysql1.err
-rw-rw---- 1 mysql mysql 1.1G 11-20 09:55 mysql-bin.000034
-rw-rw---- 1 mysql mysql 1.1G 11-20 11:31 mysql-bin.000035
-rw-rw---- 1 mysql mysql 1.1G 11-20 13:16 mysql-bin.000036
-rw-rw---- 1 mysql mysql 1.1G 11-20 14:48 mysql-bin.000037
-rw-rw---- 1 mysql mysql 722 11-20 14:48 mysql-bin.index
-rw-rw---- 1 mysql mysql 1.0G 11-20 15:48 ib_logfile1
-rw-rw---- 1 mysql mysql 1.0G 11-20 15:48 ib_logfile0
-rw-rw---- 1 mysql mysql 762M 11-20 15:48 ibdata1
-rw-rw---- 1 mysql mysql 616M 11-20 15:49 mysql-bin.000038
-rw-rw---- 1 mysql mysql 136M 11-20 15:49 mysql1-slow.log
[root@mysql1 data]# du -sh
40G
[root@mysql1 ~]# su - mysql
-bash-3.2$ mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 485929
Server version: 5.5.39-log MySQL Community Server (GPL)
Copyright (c) 2000, 2014, 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
+------------------+------------+
mysql-bin.000001 107
mysql-bin.000002 126
mysql-bin.000003 1214
mysql-bin.000004 512
mysql-bin.000005 1074661758
mysql-bin.000006 1073939583
mysql-bin.000007 1074331899
mysql-bin.000008 1074136162
mysql-bin.000009 1074403005
mysql-bin.000010 1073971338
mysql-bin.000011 1074020827
mysql-bin.000012 1073741974
mysql-bin.000013 1073742634
mysql-bin.000014 1073742508
mysql-bin.000015 257488709
mysql-bin.000016 126
mysql-bin.000017 11040
mysql-bin.000018 20686
mysql-bin.000019 126
mysql-bin.000020 41626
mysql-bin.000021 25005
mysql-bin.000022 1073742149
mysql-bin.000023 1078003457
mysql-bin.000024 1146231102
mysql-bin.000025 1356550767
mysql-bin.000026 1073741872
mysql-bin.000027 1073742085
mysql-bin.000028 1073742848
mysql-bin.000029 1073742292
mysql-bin.000030 1073742200
mysql-bin.000031 1073742231
mysql-bin.000032 908219529
mysql-bin.000033 1685174
mysql-bin.000034 1073743086
mysql-bin.000035 1073742929
mysql-bin.000036 1074674633
mysql-bin.000037 1073741987
mysql-bin.000038 638841138
+------------------+------------+
38 rows in set (0.00 sec)
mysql> PURGE MASTER LOGS BEFORE '2014-11-10 00:00:00';
Query OK, 0 rows affected (2 min 26.46 sec)
mysql> SHOW MASTER LOGS;
+------------------+------------+
Log_name File_size
+------------------+------------+
mysql-bin.000026 1073741872
mysql-bin.000027 1073742085
mysql-bin.000028 1073742848
mysql-bin.000029 1073742292
mysql-bin.000030 1073742200
mysql-bin.000031 1073742231
mysql-bin.000032 908219529
mysql-bin.000033 1685174
mysql-bin.000034 1073743086
mysql-bin.000035 1073742929
mysql-bin.000036 1074674633
mysql-bin.000037 1073741987
mysql-bin.000038 679672730
+------------------+------------+
13 rows in set (0.00 sec)
mysql> Bye
-bash-3.2$
-bash-3.2$ pwd
/home/mysql
-bash-3.2$ cd /usr/local/mysql/data/
-bash-3.2$ ls -l
total 16771440
drwx------ 2 mysql mysql 20480 Nov 18 14:51 eduportal
-rw-rw---- 1 mysql mysql 799014912 Nov 20 16:12 ibdata1
-rw-rw---- 1 mysql mysql 1073741824 Nov 20 16:12 ib_logfile0
-rw-rw---- 1 mysql mysql 1073741824 Nov 20 16:12 ib_logfile1
-rw-rw---- 1 mysql mysql 1073741824 Oct 24 02:57 ib_logfile2
drwx------ 2 mysql mysql 4096 Sep 22 18:04 mysql
-rw-r----- 1 mysql root 22225 Nov 20 05:48 mysql1.err
-rw-r----- 1 mysql root 409764613 Oct 24 01:52 mysql1.err.old
-rw-rw---- 1 mysql mysql 5 Nov 20 05:48 mysql1.pid
-rw-rw---- 1 mysql mysql 143396897 Nov 20 16:13 mysql1-slow.log
-rw-rw---- 1 mysql mysql 82840738 Oct 24 00:08 mysql1-slow.log.old
-rw-rw---- 1 mysql mysql 1073741872 Nov 13 16:14 mysql-bin.000026
-rw-rw---- 1 mysql mysql 1073742085 Nov 18 16:55 mysql-bin.000027
-rw-rw---- 1 mysql mysql 1073742848 Nov 19 14:58 mysql-bin.000028
-rw-rw---- 1 mysql mysql 1073742292 Nov 19 17:52 mysql-bin.000029
-rw-rw---- 1 mysql mysql 1073742200 Nov 19 19:50 mysql-bin.000030
-rw-rw---- 1 mysql mysql 1073742231 Nov 19 21:38 mysql-bin.000031
-rw-rw---- 1 mysql mysql 908219529 Nov 20 05:44 mysql-bin.000032
-rw-rw---- 1 mysql mysql 1685174 Nov 20 05:48 mysql-bin.000033
-rw-rw---- 1 mysql mysql 1073743086 Nov 20 09:55 mysql-bin.000034
-rw-rw---- 1 mysql mysql 1073742929 Nov 20 11:31 mysql-bin.000035
-rw-rw---- 1 mysql mysql 1074674633 Nov 20 13:16 mysql-bin.000036
-rw-rw---- 1 mysql mysql 1073741987 Nov 20 14:48 mysql-bin.000037
-rw-rw---- 1 mysql mysql 852472936 Nov 20 16:13 mysql-bin.000038
-rw-rw---- 1 mysql mysql 247 Nov 20 15:50 mysql-bin.index
drwx------ 2 mysql mysql 4096 Sep 22 18:04 performance_schema
drwx------ 2 mysql mysql 12288 Nov 19 14:07 portal
drwxr-x--- 2 mysql mysql 4096 Sep 22 18:54 test
-bash-3.2$ du -sh
27G