linux上清除mysql的單位G,大級別的日誌檔案
阿新 • • 發佈:2019-01-04
我的mysql日誌檔案大小如下: ll -h -rw-rw---- 1 mysql mysql 1.1G Dec 22 14:23 mysql-bin.000054 -rw-rw---- 1 mysql mysql 1.1G Dec 23 11:44 mysql-bin.000055 -rw-rw---- 1 mysql mysql 1.1G Dec 24 04:11 mysql-bin.000056 -rw-rw---- 1 mysql mysql 1.1G Dec 24 21:39 mysql-bin.000057 -rw-rw---- 1 mysql mysql 1.1G Dec 25 18:52 mysql-bin.000058 -rw-rw---- 1 mysql mysql 1.1G Dec 26 16:32 mysql-bin.000059 -rw-rw---- 1 mysql mysql 1.1G Dec 27 14:50 mysql-bin.000060 -rw-rw---- 1 mysql mysql 1.1G Dec 28 12:35 mysql-bin.000061 -rw-rw---- 1 mysql mysql 1.1G Dec 29 10:07 mysql-bin.000062 -rw-rw---- 1 mysql mysql 1.1G Dec 30 00:50 mysql-bin.000063 -rw-rw---- 1 mysql mysql 1.1G Dec 30 21:48 mysql-bin.000064 -rw-rw---- 1 mysql mysql 1.1G Dec 31 20:11 mysql-bin.000065 -rw-rw---- 1 mysql mysql 935M Jan 1 16:46 mysql-bin.000066
解決: 1:先檢視slave的主從進度(一下是已全部同步了主庫的中繼日誌) show slave status\G; Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it 2:再主庫上清空日誌,並檢視新的日誌檔案和偏移量 reset master;show master status; 3:從庫上停止slave再重新指定主庫資訊 stop slave; change master to master_log_file='日子名稱',master_log_pos=偏移量; start slave; 4:主庫再檢視日誌檔案 ll -h -rw-rw---- 1 mysql mysql 6.4M Jan 1 16:57 mysql-bin.000001
注意事項:
mysql開啟日誌的話,設定自動清理日誌
vim /etc/my.cnf
[mysqld]
expire_logs_days = 10 #自動清理日誌,只保留10天的日誌檔案