mysql 8小时断开连接的解决方法
1、增加 MySQL 的 wait_timeout 属性的值,修改mysql安装目录下的配置文件 my.ini文件(如果没有此文件,复制“my-default.ini”文件,生成“复件 my-default.ini”文件。将“复件 my-default.ini”文件重命名成“my.ini”),打开计算机,找到mysql的安装目录,默认是:C:\Program Files\MySQL\MySQL Server 5.5,在文件中设置:wait_timeout=31536000 ;interactive_timeout=31536000
2、减少连接池内连接的生存周期,减少连接池内连接的生存周期,使之小于上一项中所设置的wait_tim髫潋啜缅eout 的值。修改 c3p0 的配置文件,在 Spring 的配置文件中设置:<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> <property name="maxIdleTime"value="1800"/> <!--other properties --> </bean>
3、定期捂执涡扔使用连接池内的连接,定期使用连接池内的连接,使得它们不会因为闲置超时而被 MySQL 断开。修改 c3p0 的配置文件,在Spring 的配置文件中设置:<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> <property name="preferredTestQuery" value="SELECT 1"/> <property name="idleConnectionTestPeriod" value="18000"/> <property name="testConnectionOnCheckout" value="true"/> </bean>