默認情況下mysql會一直保留mysql-bin文件,這樣到一定時候,磁盤可能會被撐滿,這時候是否可以刪除這些文件呢,是否可以安全刪除,是個問題。
首先要說明一下,這些文件都是mysql的日志文件,如果不做主從復制的話,基本上是沒用的,雖然沒用,但是不建議使用rm命令刪除,這樣有可能會不安全,正確的方法是通過mysql的命令去刪除。
mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2819416 Server version: 5.5.24-0ubuntu0.12.04.1-log (Ubuntu) Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/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天的日志,這樣老日志會自動被清理掉。