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的帮助,以上均为他所整理。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值