MySQL - Error - Lost connection to MySQL server

出現報錯 "Lost connection to MySQL server"時,可能是什麼原因:
官網[1]做出如下解釋:
There are three likely causes for this error message.
Usually it indicates network connectivity trouble and you should check the condition of your network if this error occurs frequently. If the error message includes “during query,” this is probably the case you are experiencing.
Sometimes the “during query” form happens when millions of rows are being sent as part of one or more queries. If you know that this is happening, you should try increasing net_read_timeout from its default of 30 seconds to 60 seconds or longer, sufficient for the data transfer to complete.
More rarely, it can happen when the client is attempting the initial connection to the server. In this case, if your connect_timeout value is set to only a few seconds, you may be able to resolve the problem by increasing it to ten seconds, perhaps more if you have a very long distance or slow connection. You can determine whether you are experiencing this more uncommon cause by using SHOW GLOBAL STATUS LIKE ‘Aborted_connects’. It will increase by one for each initial connection attempt that the server aborts. You may see “reading authorization packet” as part of the error message; if so, that also suggests that this is the solution that you need.
If the cause is none of those just described, you may be experiencing a problem with BLOB values that are larger than max_allowed_packet, which can cause this error with some clients. Sometime you may see an ER_NET_PACKET_TOO_LARGE error, and that confirms that you need to increase max_allowed_packet.

所以可以根據情況,嘗試更改參數。
1)max_allowed_pa​​cket [2]: 一個數據包或任何生成的/中間的字符串的最大大小。此參數的默認大小爲4MB,最大可用值1073741824。您可以嘗試將其設爲最大值,理想情況下,大數據包應該沒有任何問題。

2)Interactive_timeout [3]: 服務器在關閉交互式連接之前等待活動的秒數。默認值爲28800秒。

3)wait_timeout [4]: 服務器在關閉非交互式連接之前等待活動的秒數。默認值爲28800秒。

4)connect_timeout [5]: mysqld服務器等待連接數據包之前以錯誤握手響應的秒數。默認值爲10秒

5)net_read_timeout [6]:在中止讀取之前等待連接中的更多數據的秒數。當服務器從客戶端讀取時,net_read_timeout是控制何時中止的超時值。此參數的默認值爲30秒。

6)net_write_timeout [7]: 在中止寫入之前等待塊寫入連接的秒數。默認值爲60秒。

[1]https://dev.mysql.com/doc/refman/5.6/en/error-lost-connection.html
[2]max_allowed_packet - https://dev.mysql.com/doc/refman/5.6/en/server-system-variables.html#sysvar_max_allowed_packet
[3]interactive_timeout - https://dev.mysql.com/doc/refman/5.6/en/server-system-variables.html#sysvar_interactive_timeout
[4]wait_timeout - https://dev.mysql.com/doc/refman/5.6/en/server-system-variables.html#sysvar_wait_timeout
[5]connect_timeout - https://dev.mysql.com/doc/refman/5.6/en/server-system-variables.html#sysvar_connect_timeout
[6]net_read_timeout - https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_net_read_timeout
[7]net_write_timeout - https://dev.mysql.com/doc/refman/5.6/en/server-system-variables.html#sysvar_net_write_timeout [8]https://github.com/maxbube/mydumper

特別感謝我的同事:rudonx的幫助,以上均爲他所整理。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章