之前發現自己10G的服務器空間大小,用了幾天就剩下5G了,自己上傳的文件才僅僅幾百M而已,到底是什麼東西佔用了這麼大空間呢?今天有時間徹底來查了一下:
mysql-log
看下上面的目錄web根目錄是放在/home 裏面的,所有文件加起來纔不到300M,而服務器上已經佔用了近5G空間,恐怖吧,最後經我一步一步查詢得知,原來是這個文件夾佔了非常多的空間資源:
mysql-log1
原來如此,是mysql文件夾下的var目錄佔用空間最大,那裏面是啥 內容呢?我們來看下:
mysql-log2
發現瞭如此多的 mysql-bin.0000X文件,這是什麼東西呢?原來這是mysql的操作日誌文件.我才幾十M的數據庫,操作日誌居然快3G大小了.
如何刪除mysql-bin.0000X 日誌文件呢?
紅色表示輸入的命令.
[root@jiucool var]# /usr/local/mysql/bin/mysql -u root -p
Enter password: (輸入密碼)
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 264001
Server version: 5.1.35-log Source distribution
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.
mysql> reset master; (清除日誌文件)
Query OK, 0 rows affected (8.51 sec)
mysql>
好了,我們再來查看下mysql文件夾佔用多少空間?
[root@jiucool var]# du -h –max-depth=1 /usr/local/mysql/
37M /usr/local/mysql/var
70M /usr/local/mysql/mysql-test
15M /usr/local/mysql/lib
448K /usr/local/mysql/include
2.9M /usr/local/mysql/share
7.6M /usr/local/mysql/libexec
17M /usr/local/mysql/bin
11M /usr/local/mysql/docs
2.9M /usr/local/mysql/sql-bench
163M /usr/local/mysql/
好了,看一下,整個mysql 目錄才佔用163M大小!OK,沒問題,既然mysql-bin.0000X日誌文件佔用這麼大空間,存在的意義又不是特別大,那麼我們就不讓它生成吧.
[root@jiucool var]# find / -name my.cnf
找到了my.cnf 即mysql配置文件,我們將log-bin=mysql-bin 這條註釋掉即可.
# Replication Master Server (default)
# binary logging is required for replication
#log-bin=mysql-bin
重啓下mysql吧.
OK,至此,操作完成. 以後再不會因爲就幾十M的數據庫大小生成N個G的日誌文件啦.
這些個日誌文件太恐怖了,我搬到這新VPS來才二十天左右,還不到一個月日誌文件居然就近3個G大小,如果一兩個月我不清除日誌文件這還得了!