在一个繁忙的Master DB Server上,BIN-LOG增长的速度是很快的,如果不定期清除,硬盘空间很快就会被充满.现在我们就用实验来说明一下MySQL清理BIN-LOG的方法
1、expire_logs_days
这个参数指定二进制日志自动删除的天数./etc/my.cnf配置expire_logs_days=N(N代表天数)
例子:
expire_logs_days=7
在MySQL运行的时候修改:
例子:
show binary logs;
show variables like '%log%';
set global expire_logs_days = 7;
2、命令手动删除
PURGE {MASTER | BINARY} LOGS TO 'LOG_NAME'
PURGE {MASTER | BINARY} LOGS BEFORE 'DATE'
例子:
PURGE MASTER LOGS TO 'mysql-bin.000144';
PURGE MASTER LOGS BEFORE '2013-12-15 18:00:00';
比如要清除7天前的BIN-LOG
PURGE MASTER LOGS BEFORE DATE_SUB( NOW( ), INTERVAL 7 DAY);
PURGE MASTER LOGS BEFORE DATE_SUB(CURRENT_DATE, INTERVAL 7 DAY);
清理BIN-LOG日志的规则
1、在每台SLAVE上执行SHOW SLAVE STATUS检查当前读取的日志文件号.
例子:
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.14.276
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000175
Read_Master_Log_Pos: 515417450
Relay_Log_File: relaylog.000349
Relay_Log_Pos: 488929887
Relay_Master_Log_File: mysql-bin.000175
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB: hole
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 488929741
Relay_Log_Space: 515417788
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 10
2、在主Master中使用SHOW MASTER LOGS获取日志
例子:
+------------------+-----------+
| Log_name | File_size |
+------------------+-----------+
| mysql-bin.000170 | 536872060 |
| mysql-bin.000171 | 536872020 |
| mysql-bin.000172 | 536872035 |
| mysql-bin.000173 | 536871243 |
| mysql-bin.000174 | 536871485 |
| mysql-bin.000175 | 503030739 |
+------------------+-----------+
3、清理日志但是不包括正在应用的.(最好在清理日志之前备份一下,这步不做也可以)
阅读(4373) | 评论(0) | 转发(1) |