miller
发布于

mysql The last packet sent successfully to the server

The last packet successfully received from the server was 18,146 milliseconds ago. The last packet sent successfully to the server was 18,146 milliseconds ago.

com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:165) ~[mysql-connector-j-8.4.0.jar!/:8.4.0]
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:55) ~[mysql-connector-j-8.4.0.jar!/:8.4.0]
at com.mysql.cj.jdbc.ConnectionImpl.setSessionMaxRows(ConnectionImpl.java:2594) ~[mysql-connector-j-8.4.0.jar!/:8.4.0]
at com.mysql.cj.jdbc.StatementImpl.executeInternal(StatementImpl.java:779) ~[mysql-connector-j-8.4.0.jar!/:8.4.0]
at com.mysql.cj.jdbc.StatementImpl.execute(StatementImpl.java:681) ~[mysql-connector-j-8.4.0.jar!/:8.4.0]
at com.zaxxer.hikari.pool.PoolBase.isConnectionAlive(PoolBase.java:169) ~[HikariCP-4.0.3.jar!/:na]
at com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:186) ~[HikariCP-4.0.3.jar!/:na]
... 8 common frames omitted
Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure
The last packet successfully received from the server was 18,146 milliseconds ago. 

set mysql

登录mysql机器。

单位是秒
SET GLOBAL wait_timeout = 28800; 
SET GLOBAL interactive_timeout = 28800;

可以查看信息 
SHOW VARIABLES LIKE 'wait_timeout';
SHOW VARIABLES LIKE 'interactive_timeout';

2 设置 java mysql 连接池 hikari 为例

spring:
  cloud:
    nacos:
      discovery:
        weight: 0 #线上负载权重为0,不参与负载 本地开发测试
  datasource:
    hikari:
      jdbc-url: jdbc:mysql://xxxxx:3306/testdb?characterEncoding=utf8&connectTimeout=3000&socketTimeout=20000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true
      username: mi
      password: Mip@tcc^2025
      driver-class-name: com.mysql.cj.jdbc.Driver
      max-lifetime: 1800000  # 要小于 wait_timeout
      keepalive-time: 300000 # 定期ping防止空闲断开
      idle-timeout: 600000 # 空闲连接超时时间
      minimum-idle: 5 # 最小空闲连接数
      maximum-pool-size: 20 # 最大连接数
      connection-test-query: SELECT 1
      connection-timeout: 30000
浏览 (56)
点赞
收藏
评论