com.mysql.jdbc.CommunicationsException: The last packet successfully received from the server was58129 seconds ago.The last packet sent successfully to the server was 58129 seconds ago, which is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.
查了一下,原来是mysql超时设置的问题,如果连接闲置8小时 (8小时内没有进行数据库操作), mysql就会自动断开连接, 要重启tomcat。
解决办法:
方法一:如果不用hibernate的话,则在 connection url中加参数: autoReconnect=true
jdbc.url=jdbc:mysql://ipaddress:3306/database?autoReconnect=true&autoReconnectForPools=true
方法二:用hibernate的话, 加如下属性:
<property name="connection.autoReconnect">true</property>
<property name="connection.autoReconnectForPools">true</property>
<property name="connection.is-connection-validation-required">true</property>
方法三:要是还用c3p0连接池:
<property name="hibernate.c3p0.acquire_increment">1</property>
<property name="hibernate.c3p0.idle_test_period">0</property>
<property name="hibernate.c3p0.timeout">0</property>
<property name="hibernate.c3p0.validate">true</property>
方法四:最不好的解决方案
使用Connector/J连接MySQL数据库,程序运行较长时间后就会报以下错误:
Communications link failure,The last packet successfully received from the server was *** millisecond ago.The last packet successfully sent to the server was *** millisecond ago。
其中错误还会提示你修改wait_timeout或是使用Connector/J的autoReconnect属性避免该错误。
后来查了一些资料,才发现遇到这个问题的人还真不少,大部分都是使用连接池方式时才会出现这个问题,短连接应该很难出现这个问题。这个问题的原因:
MySQL服务器默认的“wait_timeout”是28800秒即8小时,意味着如果一个连接的空闲时间超过8个小时,MySQL将自动断开该 连接,而连接池却认为该连接还是有效的(因为并未校验连接的有效性),当应用申请使用该连接时,就会导致上面的报错。
1.按照错误的提示,可以在JDBC URL中使用autoReconnect属性,实际测试时使用了autoReconnect=true& failOverReadOnly=false,不过并未起作用,使用的是5.1版本,可能真像网上所说的只对4之前的版本有效。
2.没办法,只能修改MySQL的参数了,wait_timeout最大为31536000即1年,在my.cnf中加入:
[mysqld]
wait_timeout=31536000
interactive_timeout=31536000
重启生效,需要同时修改这两个参数。
相关推荐
autoReconnect=true</property> <property name="user">root</property> <property name="password">password</property> <property name="initialPoolSize">10</property> <property name="minPoolSize">10</...
一.开发环境 IDEA + JDK8 + MySQL5.7 + navicate 二.技术栈 Springboot+Mybatis+layui 三....数据库地址url修改为 spring.datasource.url=jdbc:mysql://localhost:3306/score?...autoReconnect=true&use
useUnicode=true&characterEncoding=GB2312&autoReconnect=true jdbc.username.mysql=root jdbc.password.mysql=root 3、 Web容器:tomcat6.x 4、 页面访问路径: 论坛首页: http://localhost:8080/bbs 后台管理...
<Resource name="zk" auth="Container" type="javax.sql.DataSource" maxActive="100" maxIdle="30" maxWait="10000" username="(此处填你的数据库用户名)" password="(此处填你的数据库密码)" driverClassName=...
autoReconnect=true&characterEncoging=utf8&zeroDateTimeBehavior=convertToNull 3. 完整的配置参数参考intouch2.war!\WEB-INF\config\config.xml 4. 配置文件config.xml中的mail.upflow.com换成实际的...
autoReconnect=true&useUnicode=true&characterEncoding=GB2312</value><br/> </parameter><br/> <parameter><br/> <name>username</name><br/> <value>root</value><br/> </parameter><br/> <parameter><br/> ...
serverTimezone=UTC&useUnicode=true&characterEncoding=utf8&autoReconnect=true&allowMultiQueries=true&useSSL=false username: root password: 123456 默认用户名和密码为 root / 123456 默认数据库名为:...
autoReconnect=true&useOldAliasMetadataBehavior=true" 中的ofbiz修改为opentaps //opentaps为创建的数据库名字 jdbc-username="ofbiz" 和 jdbc-password="ofbiz" 中的ofbiz修改为mysql上创建了的用户名和密码...
autoReconnect=true&useUnicode=true&characterEncoding=GB2312</value><br/> </parameter><br/> <parameter><br/> <name>username</name><br/> <value>root</value><br/> </parameter><br/> <parameter><br/> ...
hibernate自动重新连接数据库proxool的使用及配置
dbcp连接池优化详解,主要是如何应对链接僵死的现象
修改mysql 8.0版本使用 server.servlet.context...characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useSSL=false&serverTimezone=GMT%2B8 db.user=root db.password=123456
autoReconnect=true&useUnicode=true&characterEncoding=utf-8</value> </property> <property name="username"> <value>empty</value> </property> <property name="password"> <value>empty</value>...
Xmx2048 -jar <jarfile> -h以获取: Usage: dbexport [options]Options: -J, --jdbc jdbc-url localhost JDBC url ensure that the correct jdbc drivers are on the classpath mysql: jdbc:mysql://localhost:3306/...
OpenAMEE 平台 在本地运行平台 在 settings.xml 中创建一个 Maven 配置文件 ...autoReconnect=true & autoReconnectForPools=true & useCompression=false</ db> < rabbitmq>localhost</ rabbitmq>
<Resource driverClassName=...autoReconnect=true" />
假定程序目录为: D:\web\WebRoot <br> 目录设置请看WebRoot.xml 中有下面这句代码: <br> <Context path="/WebRoot" docBase="D:/web/WebRoot" debug="0" reloadable="true" > <br>3.假定mysql数据库名为...
在Docker上使用MySQL docker运行--name some-mysql -h localhost -p 3306:3306 -e MYSQL_ROOT_PASSWORD = sifre -d mysql 示例用户和角色(运行sql命令...autoreconnect=true" password: "sifre" username: "root
数据库对象 Java 轻量级库,用于在基于 JDBC 的关系数据库中存储和... autoReconnect=true maxReconnects=3 用法 定义一个实体: @DbEntity(name = "user") public class User { ..... } 定义一个属性: @Db
#demo中有一个对数据库的简单操作,数据库链接句柄net.pocrd.demo.datasource.url=jdbc:mysql://127.0.0.1:3306/demo?autoReconnect=true&useUnicode=true&characterset=utf-8#数据库用户名...