安全刪除MySql二進制日誌

安全刪除MySql二進制日誌

mysql>SHOW MASTER LOGS;

此命令顯示目前二進制日誌的數目。

然後mysql> PURGE MASTER LOGS TO ‘binary-log.xxx’;

除了命令中給出的日誌之後的外,其他的二進制日誌全部刪除。

具體如下:PURGE MASTER LOGS PURGE { MASTER|BINARY } LOGS TO ‘log_name’PURGE { MASTER|BINARY } LOGS BEFORE ‘date’ Deletes all the binary logs listed in the log index that are strictly prior to the specified log or date. The logs also are removed from this list recorded in the log index file, so that the given log now becomes the first. Example: PURGE MASTER LOGS TO ‘mysql-bin.010′;

PURGE MASTER LOGS BEFORE ‘2003-04-02 22:46:26′;

 The BEFORE variant is available in MySQL 4.1;

 its date argument can be in ‘YYYY-MM-DD hh:mm:ss’ format. MASTER and BINARY are synonyms, though BINARY can be used only as of MySQL 4.1.1. If you have an active slave that is currently reading one of the logs you are trying to delete, this command does nothing and fails with an error. However, if you have a dormant slave, and happen to purge one of the logs it wants to read, the slave will be unable to replicate once it comes up. The command is safe to run while slaves are replicating. You do not need to stop them. You must first check all the slaves with SHOW SLAVE STATUS to see which log they are reading, then do a listing of the logs on the master with SHOW MASTER LOGS, find the earliest log among all the slaves (if all the slaves are up to date, this will be the last log on the list), backup all the logs you are about to delete (optional) and purge up to the target log.

MySQL二進制日誌
 
 

MySQL二進制日誌是以事務安全的方式包含更新日誌中可用的所有信息。它包含了所有更新了數據或者已經潛在更新了數據(例如,沒有匹配任何行的一個DELETE)的所有語句。語句以“事件”的形式保存,它描述數據更改。

運行服務器時若啓用二進制日誌則性能大約慢1%。但是,二進制日誌的好處,即用於恢復並允許設置複製超過了這個小小的性能損失。

mysqld選項來控制二進制日誌

--binlog-do-db=db_name

db_name更新記錄到二進制日誌中

--binlog-ignore-db=db_name

不將db_name更新保存到二進制日誌中

MySQL二進制日誌佔據硬盤空間。要想釋放空間,應隨時清空。操作方法是刪掉不再使用的二進制日誌,例如進行完全備份時:

shell> mysqldump --single-transaction --flush-logs --master-data=2
           --all-databases --delete-master-logs > backup_sunday_1_PM.sql

釋:如果你的服務器爲複製主服務器,用mysqldump --delete-master-logs刪掉MySQL二進制日誌很危險,因爲從服務器可能還沒有完全處理該二進制日誌的內容。

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