赞
踩
1.springboot + druid + mysql 在查询某些比较耗时的sql会报错
2.问题说明
查询数据量较小时不会报错,数据量大时会报错,报错信息如下:
com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
The last packet successfully received from the server was **10,010** milliseconds ago. The last packet sent successfully to the server was 10,010 milliseconds ago.
3.问题解决:
(1)sql上增加分页限制不会报错;
(2)从报错信息来看,这里设置的超时是10000毫秒,debug mysql-connector源码,发现有socketTimeout参数的值正好是10000,于是在datasource.url后面socketTimeout参数配置,重启测试发现能被正确识别,正常。
我的参考示例,最后两个参数:
url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.master.name}?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true&connectTimeout=10000&socketTimeout=30000
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。