赞
踩
> 方式一:docker-compose.yaml 安装数据库时,使用 command (推荐)
> 方式二:修改 my.cnf(/etc/my.cnf 文件所在位置)
IDEA 2021
JEECG BOOT 3.6
MYSQL 5.7
Spring boot 2.7.10
启动报错
- The last packet successfully received from the server was 11,012 milliseconds ago. The last packet sent successfully to the server was 11,012 milliseconds ago.
-
MySQL连接已经超时了,即长时间没有收到新的查询请求。连接处于空闲状态而被MySQL服务器关闭。
你可以尝试使用以下方法来解决这个问题:
检查数据库服务器和应用服务器之间的网络连接是否正常,特别是在高延迟或不稳定的网络环境下。
增加数据库连接的超时时间,这可以通过在JDBC URL中添加"autoReconnect=true&autoReconnectForPools=true&connectTimeout=30000&socketTimeout=60000"参数实现(具体数值可以根据实际情况调整)。
使用 数据库连接池来管理连接,可以更好地控制连接的超时时间和重连逻辑。
检查数据库是否已满,如果数据库已经使用了大量的系统资源,那么此时数据库的性能可能很低,以至于无法响应新的查询请求。
分 mysql 数据库设置 + java中mysql连接设置
show variables like '%timeout%';
- mysql:
- image: mysql:5.7.28
- container_name: mysql
- ports:
- - 3306:3306
- restart: always
- environment:
- TZ: Asia/Shanghai
- MYSQL_ROOT_PASSWORD: jeecg123456
- command:
- --connect_timeout=60
- --max_connections=16000
- --max_user_connections=2000
- --interactive_timeout=1200000
- --wait_timeout=1200000
- --character-set-server=utf8mb4
- --collation-server=utf8mb4_general_ci
- --default-authentication-plugin=mysql_native_password
- --lower_case_table_names=1
- volumes:
- - ./mysql/data:/var/lib/mysql
- - ./mysql/conf/my.cnf:/etc/mysql/my.cnf
- deploy:
- resources:
- limits:
- memory: 1G
- reservations:
- memory: 500M

- wait_timeout=1200000
- interactive_timeout=1200000
> 连接mysql url添加参数
&keepAlive=true&autoReconnect=true&autoReconnectForPools=true&connectTimeout=30000&socketTimeout=60000
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。