Discussion
This error can happen when the client is attempting an initial connection to the server. If your connect_timeout value is set to only a few seconds, you may be able to resolve the problem by increasing it.
Solution
Before increasing the value of connect_timeout, first determine its current value. This can be done by executing the following SQL statement:
SHOW VARIABLES LIKE 'connect_timeout'; +-----------------+-------+ | Variable_name | Value | +-----------------+-------+ | connect_timeout | 2 | +-----------------+-------+
Normally, setting this variable to ten seconds would be sufficient. You might want to set it to more than ten seconds if you have a very long distance or slow connection. You can determine whether you are experiencing this more uncommon cause by using the following SQL statement:
SHOW STATUS like 'aborted_connections';
This statement usually will return an empty set. However, if you have been experiencing aborted connections, the value will increase by one for each initial connection attempt that the server aborts.
To change this value of connect_timeout, you can use the SET statement. You will need SUPER privileges.
SET GLOBAL connect_timeout = 20;
本文介绍了解决数据库连接超时问题的方法。通过调整 connect_timeout 参数,可以有效避免因客户端与服务器初次连接时出现的超时错误。文章首先展示了如何查看当前的 connect_timeout 设置,并提供了增加该参数值的具体 SQL 语句。
3907

被折叠的 条评论
为什么被折叠?



