MySQL mysql-bin log檔案如何rotate/remove?

Ref:
http://dev.mysql.com/doc/refman/5.0/en/log-file-maintenance.html
http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html#sysvar_expire_logs_days
http://dev.mysql.com/doc/refman/5.0/en/purge-binary-logs.html

環境
CentOS 5 x86_64 with MySQL 5.0.95

問題
為了提升MySQL效能有將/etc/my.cnf改成使用/usr/share/mysql/my-huge.cnf
套用/usr/share/mysql/my-huge.cnf後就會enable mysql bin log (for replication/cluster)

# Replication Master Server (default)
# binary logging is required for replication
log-bin=mysql-bin

此設定預設沒有啟動自動logrotate機制跑久了硬碟鐵定爆炸

解法1.1 (自動定期刪除)(修改設定檔)(是否正確生效待驗證)
於/etc/my.cnf加入下面這行 (超過3天的自動移除)

expire_logs_days=3

解法1.2 (自動定期刪除)(動態修改系統變數)

SHOW VARIABLES WHERE Variable_Name='expire_logs_days';
SET GLOBAL expire_logs_days = 1;
SHOW VARIABLES WHERE Variable_Name='expire_logs_days';

 

解法2 (人工刪除)

PURGE BINARY LOGS TO 'mysql-bin.000010';
PURGE BINARY LOGS BEFORE '2008-04-02 22:46:26';

 

Todo
CentOS 6驗證

Facebook Comments Box

Leave a Reply