在druid中,日志输出报错discard long time none received connection. , jdbcUrl...........的信息,但是对我们使用不会有影响,只是会影响性能,但作为强迫症的我,怎么会忍心看着这个ERROR呢?
解决办法:
如果是配置文件
shardingsphere:
enabled: true # 是否启用sharding,不启用时使用datasource配置的数据源
datasource:
names: master,slave0 # 节点名称,多个时使用逗号隔开
master:
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://mysql11.ro.com.cn/gzsz?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&serverTimezone=Asia/Shanghai
username: root
password: root
# 以下为druid配置,可以共用datasource中的druid配置,需要覆盖时再重新配置
filters: stat
initial-size: 1
max-active: 20
min-idle: 1
max-wait: 60000
use-ping-method: false
slave0:
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://mysql11.rw.com.cn/gzsz?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&serverTimezone=Asia/Shanghai
username: root
password: root
# 以下为druid配置,可以共用datasource中的druid配置,需要覆盖时再重新配置
filters: stat
initial-size: 1
max-active: 20
min-idle: 1
max-wait: 60000
use-ping-method: false
masterslave:
name: ms
master-data-source-name: master
slave-data-source-names: slave0
props:
# 打印SQL
sql.show: true
check:
table:
metadata: true
# 是否在启动时检查分表元数据一致性
enabled: true
query:
with:
cipher:
column: true
在druid配置中加上use-ping-method: false
如果是在代码中:
public void configFromProperties(Properties properties) {
String property = properties.getProperty("druid.mysql.usePingMethod");
if ("true".equals(property)) {
setUsePingMethod(true);
} else if ("false".equals(property)) {
setUsePingMethod(false);
}
}
在运行参数中增加:-Ddruid.mysql.usePingMethod=false
至于为什么,布吉岛!!!!