(轉)mysql 日誌文件mysql-bin文件清除方法,和mysql-bin相關文件的配置

默認情況下mysql會一直保留mysql-bin文件,這樣到一定時候,磁盤可能會被撐滿,這時候是否可以刪除這些文件呢,是否可以安全刪除,是個問題。

首先要說明一下,這些文件都是mysql的日誌文件,如果不做主從複製的話,基本上是沒用的,雖然沒用,但是不建議使用rm命令刪除,這樣有可能會不安全,正確的方法是通過mysql的命令去刪除。

mysql -u root -p
Enter password:Welcome to the MySQL monitor.Commandsendwith;or \g.YourMySQL connection id is2819416Server version:5.5.24-0ubuntu0.12.04.1-log (Ubuntu)Copyright(c)2000,2011,Oracleand/or its affiliates.All rights reserved.Oracleis a registered trademark of OracleCorporationand/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> reset master;Query OK,0 rows affected (3 min 37.65 sec)

其實關鍵的命令就是reset master;這個命令會清空mysql-bin文件。

另外如果你的mysql服務器不需要做主從複製的話,建議通過修改my.cnf文件,來設置不生成這些文件,只要刪除my.cnf中的下面一行就可以了。

log-bin=mysql-bin

如果你需要複製,最好控制一下這些日誌文件保留的天數,可以通過下面的配置設定日誌文件保留的天數:

expire_logs_days =7

表示保留7天的日誌,這樣老日誌會自動被清理掉。

發佈了78 篇原創文章 · 獲贊 0 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章