centos mysql佔用磁碟空間過大解決方法
阿新 • • 發佈:2018-12-30
安裝了mysql以後,過一段時間發現磁碟空間不足了,查一下,發現是 mysql-bin.000001、 mysql-bin .000002等檔案佔用了空間,那麼這些檔案是幹嗎的?這是資料庫的操作日誌,例如UPDATE一個表,或者DELETE一些資料,即使該語句沒有匹配的資料,這個命令也會儲存到日誌檔案中,還包括每個語句執行的時間,也會記錄進去的。
這樣做主要有以下兩個目的:
1:資料恢復
如果你的資料庫出問題了,而你之前有過備份,那麼可以看日誌檔案,找出是哪個命令導致你的資料庫出問題了,想辦法挽回損失。
2:主從伺服器之間同步資料
主伺服器上所有的操作都在記錄日誌中,從伺服器可以根據該日誌來進行,以確保兩個同步。
解決方法:
root@chinaitlabs.net]# /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> resetmaster; (清除日誌檔案) Query OK, 0 rows affected (8.51 sec) mysql>
好了,我們再來檢視下mysql資料夾佔用多少空間?
[root@chinaitlabs.net]# 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]# vi /etc/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的日誌檔案。
原文地址:
http://www.tuicool.com/articles/VJ7BFb