mysql 连接超时异常
mysql 连接超时错误 自己的小网站在测试机器上长时间不访问后(默认8小时过期),再次访问发现有如下错误: Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received fro m the server was 63,020,509 m
mysql 连接超时错误自己的小网站在测试机器上长时间不访问后(默认8小时过期),再次访问发现有如下错误:
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received fro
m the server was 63,020,509 milliseconds ago. ?The last packet sent successfully to the server was 63,020,509
?milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either e
xpiring and/or testing connection validity before use in your application, increasing the server configured v
alues for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this pr
oblem.
? ? ? ? at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
? ? ? ? at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
? ? ? ? at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:4
5)
? ? ? ? at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
? ? ? ? at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
? ? ? ? at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1116)
? ? ? ? at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3851)
? ? ? ? at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2471)
? ? ? ? at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2651)
? ? ? ? at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2683)
? ? ? ? at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2144)
? ? ? ? at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1379)
? ? ? ? at org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:172)
? ? ? ? at org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:172)
?
Fix:?If only the connection pool could check if the the connection it is about to return is live or not, the porblem is fixed. This can be done in apache-common-dbcp (I know this one coz I used it, please look into documentation of the connection-pool you are using). Here’s how you do it: You add the following properties to dbcp configuration.
- validationQuery=”SELECT 1″
- testOnBorrow=”true”
And that does the trick.
?
暂时我对我的mysql连接加上: 试试效果
validationQuery
=
"SELECT 1"
?
testOnBorrow
=
"true"
?
目前我不想添加: ?autoReconnect=true? 因为我对此的理解不深,mysql文档这样写的:
?
This parameter is?false
?by default. This forces disconnected API nodes (including MySQL Servers acting as SQL nodes) to use a new connection to the cluster rather than attempting to re-use an existing one, as re-use of connections can cause problems when using dynamically-allocated node IDs. (Bug #45921)
如果有问题再添加 autoReconnect选项
like this:
?
? ? ? ? ? ? ? ?initialSize="10" maxActive="100" maxIdle="30" maxWait="10000"
? ? ? ? ? ? ? ?username="***" password="***" driverClassName="com.mysql.jdbc.Driver"
? ? ? ? ? ? ? ?url="jdbc:mysql://localhost:3306/saasNetTest"
? ? ? ? ? ? ? ?validationQuery="SELECT 1"
? ? ? ? ? ? ? ?testOnBorrow="true"
?
? ? />
?
参考文档:http://stackoverflow.com/questions/9674165/mysql-jdbc-timeout-even-with-autoreconnect-true
http://amitcodes.com/2008/07/26/16/
http://www.tomcatexpert.com/blog/2010/04/01/configuring-jdbc-pool-high-concurrency
?

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

热门话题

MySQL适合初学者使用,因为它安装简单、功能强大且易于管理数据。1.安装和配置简单,适用于多种操作系统。2.支持基本操作如创建数据库和表、插入、查询、更新和删除数据。3.提供高级功能如JOIN操作和子查询。4.可以通过索引、查询优化和分表分区来提升性能。5.支持备份、恢复和安全措施,确保数据的安全和一致性。

MySQL是一个开源的关系型数据库管理系统。1)创建数据库和表:使用CREATEDATABASE和CREATETABLE命令。2)基本操作:INSERT、UPDATE、DELETE和SELECT。3)高级操作:JOIN、子查询和事务处理。4)调试技巧:检查语法、数据类型和权限。5)优化建议:使用索引、避免SELECT*和使用事务。

可以通过以下步骤打开 phpMyAdmin:1. 登录网站控制面板;2. 找到并点击 phpMyAdmin 图标;3. 输入 MySQL 凭据;4. 点击 "登录"。

使用 Navicat Premium 创建数据库:连接到数据库服务器并输入连接参数。右键单击服务器并选择“创建数据库”。输入新数据库的名称和指定字符集和排序规则。连接到新数据库并在“对象浏览器”中创建表。右键单击表并选择“插入数据”来插入数据。

MySQL和SQL是开发者必备技能。1.MySQL是开源的关系型数据库管理系统,SQL是用于管理和操作数据库的标准语言。2.MySQL通过高效的数据存储和检索功能支持多种存储引擎,SQL通过简单语句完成复杂数据操作。3.使用示例包括基本查询和高级查询,如按条件过滤和排序。4.常见错误包括语法错误和性能问题,可通过检查SQL语句和使用EXPLAIN命令优化。5.性能优化技巧包括使用索引、避免全表扫描、优化JOIN操作和提升代码可读性。

可在 Navicat 中通过以下步骤新建 MySQL 连接:打开应用程序并选择“新建连接”(Ctrl N)。选择“MySQL”作为连接类型。输入主机名/IP 地址、端口、用户名和密码。(可选)配置高级选项。保存连接并输入连接名称。

直接从数据库中恢复被删除的行通常是不可能的,除非有备份或事务回滚机制。关键点:事务回滚:在事务未提交前执行ROLLBACK可恢复数据。备份:定期备份数据库可用于快速恢复数据。数据库快照:可创建数据库只读副本,在数据误删后恢复数据。慎用DELETE语句:仔细检查条件,避免误删数据。使用WHERE子句:明确指定要删除的数据。使用测试环境:在执行DELETE操作前进行测试。

Redis 使用单线程架构,以提供高性能、简单性和一致性。它利用 I/O 多路复用、事件循环、非阻塞 I/O 和共享内存来提高并发性,但同时存在并发性受限、单点故障和不适合写密集型工作负载的局限性。
