收到客戶反饋有時接口報504,查看應用日志發現故障期間數據庫連接失敗
com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failureThe last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server
在到數據庫服務器查看系統日志/var/log/messages
發現數據庫有重啟
在查看mysqld.log發現 11:46確實有一些錯誤日志
搜了網上一些文章,這篇跟我的日志比較吻合
MySQL數據庫會莫名其妙地重新啟動(adaptive hash index) - 墨天輪
自適應hash索引是什么鬼?
確實是打開的
通過命令設置關閉:set global innodb_adaptive_hash_index=0;
但最好還是在配置文件添加避免服務器重啟不生效,最終調整了幾個參數如下,看看后面還會不會重啟。
[mysqld]
slow_query_log=1? ? # 開啟慢sql查詢
long_query_time=2 #查詢時間大于2秒的為慢sql
innodb_buffer_pool_size=4G? #緩存大小默認是16M,建議設置為總內存的70%
innodb_adaptive_hash_index=OFF?
?