For business reasons, you can't keep logs for a fixed number of days, and you can't have the disk space station full, so you can only delete binlog manually.
Using the Purge command that comes with MySQL
PURGE MASTER LOGS to ' mysql-bin.000002 '; Delete the Binlog log before 002 (not including 002),
[[email protected] data]# ls
DBmaster.test.err ib_logfile0 localhost.pid mysql-bin.000002 mysql-bin.000005 performance_schema wine_test
DBmaster.test.pid ib_logfile1 mysql mysql-bin.000003 mysql-bin.000006 test
Ibdata1 localhost.err mysql-bin.000001 mysql-bin.000004 mysql-bin.index WINE_CN
Mysql> PURGE MASTER LOGS to ' mysql-bin.000002 ';
[[email protected] data]# ls
DBmaster.test.err ib_logfile0 localhost.pid mysql-bin.000003 mysql-bin.000006 test
DBmaster.test.pid ib_logfile1 MySQL mysql-bin.000004 mysql-bin.index wine_cn
Ibdata1 localhost.err mysql-bin.000002 mysql-bin.000005 performance_schema wine_test
PURGE MASTER LOGS to ' mysql-bin.000005 ';
[[email protected] data]# ls
DBmaster.test.err ibdata1 ib_logfile1 localhost.pid mysql-bin.000005 mysql-bin.index test wine_test
DBmaster.test.pid ib_logfile0 localhost.err MySQL mysql-bin.000006 performance_schema wine_cn
[Email protected] data]#
#!/bin/bash
# date:2014-06-11
# Database Delete-ge 30day binlog Feil
Cd/dbdata/mysql
#logname = (' Find '/-maxdepth 1-type f-mtime +30-name ' mysql-bin.* ' |sed-n ' 1p;\ $p ' |awk-f '/' {print $} ')
Logname= ' Find/-maxdepth 1-type f-mtime +30-name "mysql-bin.*" |sed-n ' $p ' |awk-f '/' {print $} '
Echo $logname
Mysql-uroot-p123456-e "PURGE MASTER LOGS to ' $logname ';"
mysql> CREATE USER ' binlog ' @ ' localhost ' identified by ' mypass123 ';
Query OK, 0 rows affected (0.05 sec)
Mysql> GRANT SUPER on * * to ' binlog ' @ ' localhost ';
Query OK, 0 rows Affected (0.00 sec)
This article is from the "Small Box" blog, please be sure to keep this source http://zhangxiaohe.blog.51cto.com/7821029/1545478
Safely remove MySQL binlog logs