说明:
当开启mysql数据库主从时,会产生大量如mysql-bin.00000* log的文件,这会大量耗费您的硬盘空间。
mysql-bin.000001
mysql-bin.000002
mysql-bin.000003
mysql-bin.000004
mysql-bin.000005
有三种解决方法:
1.关闭mysql主从,关闭binlog;
2.开启mysql主从,设置expire_logs_days;
3.手动清除binlog文件,> PURGE MASTER LOGS TO ‘MySQL-bin.010′;
1.关闭mysql主从,关闭binlog
# vim /etc/my.cnf //注释掉log-bin,binlog_format
# Replication Master Server (default)
# binary logging is required for replication
# log-bin=mysql-bin
# binary logging format - mixed recommended
# binlog_format=mixed
然后重启数据库
2.重启mysql,开启mysql主从,设置expire_logs_days
# vim /etc/my.cnf //修改expire_logs_days,x是自动删除的天数,一般将x设置为短点,如10
expire_logs_days = x //二进制日志自动删除的天数。默认值为0,表示“没有自动删除”
此方法需要重启mysql,附录有关于expire_logs_days的英文说明
当然也可以不重启mysql,开启mysql主从,直接在mysql里设置expire_logs_days
> show binary logs;
> show variables like '%log%';
> set global expire_logs_days = 10;
3.手动清除binlog文件
# /usr/local/mysql/bin/mysql -u root -p
> PURGE MASTER LOGS BEFORE DATE_SUB(CURRENT_DATE, INTERVAL 10 DAY); //删除10天前的MySQL binlog日志,附录2有关于PURGE MASTER LOGS手动删除用法及示例
> show master logs;
也可以重置master,删除所有binlog文件:
# /usr/local/mysql/bin/mysql -u root -p
> reset master; //附录3有清除binlog时,对从mysql的影响说明