現象:java
程序會不定時的出現鏈接錯誤,問題bug的異常信息以下:mysql
The last packet successfully received from the server was 116 milliseconds ago. The last packet sent successfully to the server was 115 milliseconds ago.sql
java.sql.SQLException: No database selected緩存
但經過客戶端sqlyog/navicat鏈接均爲正常。bash
----------------------------------------------------------------------
ide
另:maxscale1.4.3有時還會出現掛起現象,4006端口直接關閉。後咱們用了watch命令後臺跑監控。url
watch -d /bin/bash /root/sh/restart_maxsacle.sh
spa
#!/bin/bash netstat -ntlp | grep maxscale | grep 4006 > /dev/null 2>&1 if [ $? -eq 1 ];then /etc/init.d/maxscale start fi
解決:5.6如下能夠直接在url上配置:autoReconnect=truerest
對於5.6以上的只能在jdbc的連接池裏設置:server
第一個設置成ture,超時自動連接,對於mysql要把第二個設置成false,不啓用緩存。
以上是開發須要注意的都是一些基本的配置。
其目的爲:每次歸還鏈接時執行select 'x'檢測鏈接是否有效。