最近將一MySQL數據庫的系統變量log_output從file調整為table后,偶爾會收到告警郵件,告警郵件內容為:
Failed to write to mysql.slow_log。
查了一下這個問題,發現居然是一個Bug,其實出現這個錯誤是因為慢查詢的SQL語句太長,導致插入mysql.slow_log系統表時超過字段的長度,所以在錯誤日志當中出現"Failed to write to mysql.slow_log"信息。官方文檔的Bug信息為Bug #37132 Logging to slow_log table fails with very slow queries。 摘抄其中一段描述內容如下:
Fixed in 8.0.17.
Logging to the mysql.slow_log system table could fail when values
were to large for table columns. Now logging proceeds on a
best-effort basis, writing what information can be provided.
Otherwise, the row is discarded and a message is written to the error log.
這個Bug直到MySQL 8.0.17才被Fix掉,在這之前從未碰到過,第一次遇到也頗感意外,遇到了就記錄一下!
參考資料:
https://bugs.mysql.com/bug.php?id=37132