首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫

解決 MySQL Slow Log 中大量 Binlog Dump 記錄的問題

     編輯:MySQL 資料庫相關知識

問題背景

在線上環境中,MySQL 的 Slow Log 經常出現大量類似以下的記錄:

# Time: 130823 13:56:08
# User@Host: repl[repl] @ slave [10.x.x.x]
# Query_time: 9.000833 Lock_time: 0.000000 Rows_sent: 1 Rows_examined: 1
SET timestamp=1377237368;
# administrator command: Binlog Dump;

每次 Binlog Dump 都會被記錄,導致 Slow Log 膨脹,干擾真正的慢查詢分析。經排查,這是 MySQL 5.1.x 版本(確認 5.1.49 存在)的已知現象。

解決方案

修改 my.cnf 配置文件,在 [mysqld] 區塊添加或修改以下選項:

log-slow-admin-statements = 0

注意: 此參數在 MySQL 5.1 中不支持動態修改,必須重啟 mysqld 才能生效。

原理說明

官方手冊對該參數的描述是:

Include slow administrative statements in the statements written to the slow query log. Administrative statements include ALTER TABLE, ANALYZE TABLE, CHECK TABLE, CREATE INDEX, DROP INDEX, OPTIMIZE TABLE, and REPAIR TABLE.

雖然手冊未明確列出 Binlog Dump,但實測關閉此選項後,Binlog Dump 記錄不再寫入 Slow Log。這說明 Binlog Dump 在內部被歸類為管理命令之一。

總結

若遇到 Slow Log 被大量 Binlog Dump 佔用,設定 log-slow-admin-statements = 0 並重啟服務即可乾淨解決。這也提醒我們:文檔有時不完全,實踐出真知。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved