mysql报错:The last packet successfully received from the server was 51,384,505 milliseconds ago.产生原因是什么?如何解决这个报错问题?

发布时间 2023-08-29 14:00:34作者: 有时B

这个报错是 MySQL 连接超时导致的。当 MySQL 客户端在一段时间内没有收到来自服务器的数据包时,会触发这个错误。

产生这个错误的可能原因有:

1. 网络问题:可能是网络连接不稳定或延迟过高,导致数据包在传输过程中丢失或延迟。
2. MySQL 服务器负载过高:如果 MySQL 服务器负载过高,无法及时响应客户端的请求,就会导致连接超时。

要解决这个问题,可以尝试以下几个方法:

1. 检查网络连接:确保网络连接稳定,并且延迟较低。可以尝试通过 ping 命令测试与 MySQL 服务器之间的网络延迟。

2. 调整连接超时设置:可以尝试增加连接超时时间,使得 MySQL 客户端在更长的时间内等待服务器响应。可以在连接字符串中设置 `connectTimeout` 参数,或者在 MySQL 配置文件中调整 `wait_timeout` 和 `interactive_timeout` 参数的值。

3. 优化 MySQL 服务器配置和性能:如果 MySQL 服务器负载过高,可以尝试优化服务器配置和性能,以提高其响应能力。可以考虑增加服务器的硬件资源(如 CPU、内存等),优化查询语句和索引,以及调整其他相关的 MySQL 参数。

4. 使用连接池:使用连接池可以减少频繁创建和关闭数据库连接的开销,提高连接的复用性和性能。可以使用一些流行的连接池库,如 HikariCP、Tomcat JDBC 等。

5. 检查服务器日志:查看 MySQL 服务器的日志文件,了解是否有其他错误或警告信息,可以帮助进一步确定问题的原因。

需要根据具体情况选择适当的解决方法。如果问题仍然存在,建议进一步分析和调试 MySQL 服务器和网络环境,或者联系相关的技术支持人员进行帮助和排查。

 

123

 

 

 1     public PriceVO getPriceById(Integer id,  OrderInfo orderInfo) {
 2         PriceVO priceVO = priceApi.getPriceById(id);
 3         if(priceVO != null){
 4             OperatorInfoVO operatorInfoVO = operatorInfoApi.getOperatorInfoById(priceVO.getOperatorId());
 5             if(operatorInfoVO != null){
 6                 priceVO.setOperatorName(operatorInfoVO.getOperatorName());
 7             }
 8         }
 9         if(orderInfo !=null){
10             if(orderInfo.getGunChargeType() == GunChargeTypeEnum.SUPER_CHARGE.getCode()){//超冲
11                 PileVO pile = pileService.getPileById(orderInfo.getPileId());
12                 for (PriceModelVO priceModelVO : priceVO.getPriceModelList()) {
13                     if(priceModelVO.getPrcServ() !=null){
14                         BigDecimal sf = priceModelVO.getPrcServ().multiply(pile.getSuperChargingRate()).multiply(new BigDecimal("0.01"));
15                         priceModelVO.setPrcServ(priceModelVO.getPrcServ().add(sf).setScale(2, RoundingMode.CEILING));
16                     }
17 
18                 }
19                 if(priceVO.getPrcServ() !=null){
20                     BigDecimal sf = priceVO.getPrcServ().multiply(pile.getSuperChargingRate()).multiply(new BigDecimal("0.01"));
21                     priceVO.setPrcServ(priceVO.getPrcServ().add(sf).setScale(2, RoundingMode.CEILING));
22                 }
23             }
24         }
25         return priceVO;
26     }