开发者社区> 问答> 正文

Mybatis报错poolPingQuery?报错

<dataSource type="POOLED">
                <property name="driver" value="${driver}" />
                <property name="url" value="${url}" />
                <property name="username" value="${username}" />
                <property name="password" value="${password}" />
                <property name="poolMaximumActiveConnections" value="900" /><!-- 同一时间内最大连接数 -->
                <property name="poolMaximumIdleConnections" value="100" /><!-- 连接最大空闲数目 -->
                <property name="poolMaximumCheckoutTime" value="10000" /><!-- 连接被每个任务占用的最大时间 -->
                <property name="poolTimeToWait" value="5000" /><!-- 连接池中无可用连接时,线程的等待时间 -->
                <property name="poolPingQuery" value="select now()" />
                <property name="poolPingEnabled" value="true" />
            </dataSource>
上面是MapperConfig配置的数据源。建立mysql连接的时候也加了autoReconnect,如下:

Reader reader = Resources.getResourceAsReader(DATA_MAPPER_FILE);
		DBConfig dbConfig = SystemConfig.getDataDBConfig();
		Properties properties = new Properties();
		properties.put("driver", "com.mysql.jdbc.Driver");
		String url = "jdbc:mysql://"
				+ host
				+ ":"
				+ port
				+ "/"
				+ dbName
				+ "?autoReconnect=true&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true";
		properties.put("url", url);
		properties.put("username", "usr");
		properties.put("password", "password");
		dataSessionFactory = new SqlSessionFactoryBuilder().build(reader,
				properties);
		reader.close();



但是服务器运行的时候,还是会隔一断时间就会报这个错误。对Mybatis不太熟悉,有人可以解答一下吗?谢谢!

178262497 [pool-3-thread-300] WARN org.apache.ibatis.datasource.pooled.PooledDataSource - Execution of ping query 'select now()' failed: The last packet successfully received fr
om the server was 133,200,879 milliseconds ago.  The last packet sent successfully to the server was 133,200,879 milliseconds ago. 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 timeout
s, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.



展开
收起
爱吃鱼的程序员 2020-06-10 09:58:24 882 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    mysql5.5还是5.6+autoReconnect已经没用了。

    你可以检查一下网络配置和数据库的timeout配置。

    2020-06-10 09:58:40
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
Java Spring Boot开发实战系列课程【第6讲】:Spring Boot 2.0实战MyBatis与优化(Java面试题) 立即下载
低代码开发师(初级)实战教程 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载