zl程序教程

您现在的位置是:首页 >  数据库

当前栏目

mysql java连接异常及断开解决秘籍

mysqlJAVA异常连接 解决 秘籍 断开
2023-09-27 14:28:33 时间


3、The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server
com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
统一加上autoReconnect=true&failOverReadOnly=false,如果是mysql 8.0,额外加上useSSL=false&serverTimezone=Asia/Shanghai。
JDBC加上验证
validationQuery=SELECT 1
testWhileIdle=true
testOnBorrow=true
testOnReturn=true

4、The last packet successfully received from the server was 1,583 milliseconds ago. The last packet sent successfully to the server was 1,583 milliseconds ago.
timeBetweenEvictionRunsMillis=300000
minEvictableIdleTimeMillis=3600000
removeAbandoned=true
removeAbandonedTimeout=180000
logAbandoned=true

4、5 https://www.cnblogs.com/zhjh256/p/6591294.html

5、ERROR : (2006, 'MySQL server has gone away'),通常答案就https://www.cnblogs.com/fnlingnzb-learner/p/5984795.html这么几个,1、服务器真的挂了;2、超时了(如果经过mycat,可能是mycat到mysql的连接已经超时了);3、网络真的很不稳定。
6、2013 Lost connection to MySQL server at 'waiting for intial communication packet',system error:0 设置参数skip-name-resolve

https://dev.mysql.com/doc/refman/5.7/en/common-errors.html

1、使用最新版本的mycat,1.3、1.4 bug较多,比如com.mysql.jdbc.PacketTooBigException: Packet for query is too large (60 > -1),参见https://www.cnblogs.com/zhjh256/p/9229568.html 

1.1、对于mycat,默认的查询超时时间300秒,如果时间很长,前端可能会出现错误"???",同时后台取消执行还是继续执行??

 

可以在server.xml中调整,如下:

<system>
<!--sql超时,单位秒-->
<property name="sqlExecuteTimeout">1800</property>
</system>
建议和mysql服务器的xxx相同。
<property name="maxPacketSize">1073741824</property>
建议和mysql服务器的xxx相同。
<property name="idleTimeout">180000</property>
建议和mysql服务器的xxx相同。
<property name="txIsolation">READ-COMMITTED</property>
建议和mysql服务器的xxx相同。
其他可https://www.cnblogs.com/kingsonfu/p/10627285.html

2、使用最新版本的mysql connector
7、mysql各超时参数时间足够长

interactive_timeout,默认28800,比wait_timeout具有更高的优先级,典型的交互式连接就是mysql自带的客户端,其他是C客户端为主。

wait_timeout,默认28800,等待非交互式连接的时间

net_read_timeout,等待下一个数据包发送的时间阈值,除了WAN和网络特别堵,基本不会发生

net_write_timeout,等待下一个数据包到来的时间阈值,除了WAN和网络特别堵,基本不会发生

mysql、mycat配置都正确,但是delete长时间执行时报下列错误:

mycat.log没有内容生成,wrapper.log大量下列错误: