无法从数据源获取连接(Hibernate + Hikari + MySQL)
Unable to acquire connection from data source(Hibernate + Hikari + MySQL)
我正在尝试使用 Hikari 作为连接池连接到本地 MySql 数据库,但我无法建立连接。
谁能告诉我哪里做错了?
MySql版本:
mysql Linux 版本 8.0.21 x86_64(MySQL 社区服务器 - GPL)
项目中的依赖如下:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-hikaricp</artifactId>
<version>5.3.6.Final</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.21</version>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>2.7.6</version>
</dependency>
HikariCP 启动日志:
2020-08-04 19:09:31.089 DEBUG [main] [com.zaxxer.hikari.HikariConfig] chapuceros-pool - configuration:
2020-08-04 19:09:31.091 DEBUG [main] [com.zaxxer.hikari.HikariConfig] allowPoolSuspension.............false
2020-08-04 19:09:31.091 DEBUG [main] [com.zaxxer.hikari.HikariConfig] autoCommit......................true
2020-08-04 19:09:31.091 DEBUG [main] [com.zaxxer.hikari.HikariConfig] catalog.........................none
2020-08-04 19:09:31.091 DEBUG [main] [com.zaxxer.hikari.HikariConfig] connectionInitSql...............none
2020-08-04 19:09:31.091 DEBUG [main] [com.zaxxer.hikari.HikariConfig] connectionTestQuery............."/* ping */"
2020-08-04 19:09:31.091 DEBUG [main] [com.zaxxer.hikari.HikariConfig] connectionTimeout...............30000
2020-08-04 19:09:31.091 DEBUG [main] [com.zaxxer.hikari.HikariConfig] dataSource......................none
2020-08-04 19:09:31.091 DEBUG [main] [com.zaxxer.hikari.HikariConfig] dataSourceClassName.............none
2020-08-04 19:09:31.092 DEBUG [main] [com.zaxxer.hikari.HikariConfig] dataSourceJNDI..................none
2020-08-04 19:09:31.092 DEBUG [main] [com.zaxxer.hikari.HikariConfig] dataSourceProperties............{autoReconnectForPools=true, cacheServerConfiguration=true, useServerPrepStmts=true, elideSetAutoCommits=true, user=chapucerodev, rewriteBatchedStatements=true, cachePrepStmts=true, cacheResultSetMetadata=true, useLocalSessionState=true, maintainTimeStats=false, prepStmtCacheSize=250, prepStmtCacheSqlLimit=2048, password=<masked>, useLocalTransactionState=true}
2020-08-04 19:09:31.092 DEBUG [main] [com.zaxxer.hikari.HikariConfig] driverClassName................."com.mysql.cj.jdbc.Driver"
2020-08-04 19:09:31.092 DEBUG [main] [com.zaxxer.hikari.HikariConfig] healthCheckProperties...........{}
2020-08-04 19:09:31.092 DEBUG [main] [com.zaxxer.hikari.HikariConfig] healthCheckRegistry.............none
2020-08-04 19:09:31.092 DEBUG [main] [com.zaxxer.hikari.HikariConfig] idleTimeout.....................90000
2020-08-04 19:09:31.092 DEBUG [main] [com.zaxxer.hikari.HikariConfig] initializationFailFast..........true
2020-08-04 19:09:31.092 DEBUG [main] [com.zaxxer.hikari.HikariConfig] initializationFailTimeout.......1
2020-08-04 19:09:31.092 DEBUG [main] [com.zaxxer.hikari.HikariConfig] isolateInternalQueries..........false
2020-08-04 19:09:31.092 DEBUG [main] [com.zaxxer.hikari.HikariConfig] jdbc4ConnectionTest.............false
2020-08-04 19:09:31.093 DEBUG [main] [com.zaxxer.hikari.HikariConfig] jdbcUrl.........................jdbc:mysql://localhost:3306/TEST_DB
2020-08-04 19:09:31.093 DEBUG [main] [com.zaxxer.hikari.HikariConfig] leakDetectionThreshold..........0
2020-08-04 19:09:31.093 DEBUG [main] [com.zaxxer.hikari.HikariConfig] maxLifetime.....................120000
2020-08-04 19:09:31.093 DEBUG [main] [com.zaxxer.hikari.HikariConfig] maximumPoolSize.................30
2020-08-04 19:09:31.093 DEBUG [main] [com.zaxxer.hikari.HikariConfig] metricRegistry..................none
2020-08-04 19:09:31.093 DEBUG [main] [com.zaxxer.hikari.HikariConfig] metricsTrackerFactory...........none
2020-08-04 19:09:31.093 DEBUG [main] [com.zaxxer.hikari.HikariConfig] minimumIdle.....................1
2020-08-04 19:09:31.093 DEBUG [main] [com.zaxxer.hikari.HikariConfig] password........................<masked>
2020-08-04 19:09:31.093 DEBUG [main] [com.zaxxer.hikari.HikariConfig] poolName........................"chapuceros-pool"
2020-08-04 19:09:31.093 DEBUG [main] [com.zaxxer.hikari.HikariConfig] readOnly........................false
2020-08-04 19:09:31.093 DEBUG [main] [com.zaxxer.hikari.HikariConfig] registerMbeans..................false
2020-08-04 19:09:31.093 DEBUG [main] [com.zaxxer.hikari.HikariConfig] scheduledExecutor...............none
2020-08-04 19:09:31.093 DEBUG [main] [com.zaxxer.hikari.HikariConfig] scheduledExecutorService........internal
2020-08-04 19:09:31.093 DEBUG [main] [com.zaxxer.hikari.HikariConfig] schema..........................none
2020-08-04 19:09:31.093 DEBUG [main] [com.zaxxer.hikari.HikariConfig] threadFactory...................internal
2020-08-04 19:09:31.093 DEBUG [main] [com.zaxxer.hikari.HikariConfig] transactionIsolation............default
2020-08-04 19:09:31.093 DEBUG [main] [com.zaxxer.hikari.HikariConfig] username........................"defaultuser"
2020-08-04 19:09:31.093 DEBUG [main] [com.zaxxer.hikari.HikariConfig] validationTimeout...............5000
错误摘要:
[main] [com.zaxxer.hikari.HikariDataSource] chapuceros-pool - Starting...
[com.zaxxer.hikari.pool.PoolBase] chapuceros-pool - Failed to create/setup connection: Communications link failure
[com.zaxxer.hikari.pool.HikariPool] chapuceros-pool - Cannot acquire connection from data source
com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure
Caused by: java.net.SocketException: Broken pipe (Write failed)
将参数 ?useSSL=false
添加到 jdbcUrl
解决了我的问题。
我正在尝试使用 Hikari 作为连接池连接到本地 MySql 数据库,但我无法建立连接。
谁能告诉我哪里做错了?
MySql版本: mysql Linux 版本 8.0.21 x86_64(MySQL 社区服务器 - GPL)
项目中的依赖如下:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-hikaricp</artifactId>
<version>5.3.6.Final</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.21</version>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>2.7.6</version>
</dependency>
HikariCP 启动日志:
2020-08-04 19:09:31.089 DEBUG [main] [com.zaxxer.hikari.HikariConfig] chapuceros-pool - configuration:
2020-08-04 19:09:31.091 DEBUG [main] [com.zaxxer.hikari.HikariConfig] allowPoolSuspension.............false
2020-08-04 19:09:31.091 DEBUG [main] [com.zaxxer.hikari.HikariConfig] autoCommit......................true
2020-08-04 19:09:31.091 DEBUG [main] [com.zaxxer.hikari.HikariConfig] catalog.........................none
2020-08-04 19:09:31.091 DEBUG [main] [com.zaxxer.hikari.HikariConfig] connectionInitSql...............none
2020-08-04 19:09:31.091 DEBUG [main] [com.zaxxer.hikari.HikariConfig] connectionTestQuery............."/* ping */"
2020-08-04 19:09:31.091 DEBUG [main] [com.zaxxer.hikari.HikariConfig] connectionTimeout...............30000
2020-08-04 19:09:31.091 DEBUG [main] [com.zaxxer.hikari.HikariConfig] dataSource......................none
2020-08-04 19:09:31.091 DEBUG [main] [com.zaxxer.hikari.HikariConfig] dataSourceClassName.............none
2020-08-04 19:09:31.092 DEBUG [main] [com.zaxxer.hikari.HikariConfig] dataSourceJNDI..................none
2020-08-04 19:09:31.092 DEBUG [main] [com.zaxxer.hikari.HikariConfig] dataSourceProperties............{autoReconnectForPools=true, cacheServerConfiguration=true, useServerPrepStmts=true, elideSetAutoCommits=true, user=chapucerodev, rewriteBatchedStatements=true, cachePrepStmts=true, cacheResultSetMetadata=true, useLocalSessionState=true, maintainTimeStats=false, prepStmtCacheSize=250, prepStmtCacheSqlLimit=2048, password=<masked>, useLocalTransactionState=true}
2020-08-04 19:09:31.092 DEBUG [main] [com.zaxxer.hikari.HikariConfig] driverClassName................."com.mysql.cj.jdbc.Driver"
2020-08-04 19:09:31.092 DEBUG [main] [com.zaxxer.hikari.HikariConfig] healthCheckProperties...........{}
2020-08-04 19:09:31.092 DEBUG [main] [com.zaxxer.hikari.HikariConfig] healthCheckRegistry.............none
2020-08-04 19:09:31.092 DEBUG [main] [com.zaxxer.hikari.HikariConfig] idleTimeout.....................90000
2020-08-04 19:09:31.092 DEBUG [main] [com.zaxxer.hikari.HikariConfig] initializationFailFast..........true
2020-08-04 19:09:31.092 DEBUG [main] [com.zaxxer.hikari.HikariConfig] initializationFailTimeout.......1
2020-08-04 19:09:31.092 DEBUG [main] [com.zaxxer.hikari.HikariConfig] isolateInternalQueries..........false
2020-08-04 19:09:31.092 DEBUG [main] [com.zaxxer.hikari.HikariConfig] jdbc4ConnectionTest.............false
2020-08-04 19:09:31.093 DEBUG [main] [com.zaxxer.hikari.HikariConfig] jdbcUrl.........................jdbc:mysql://localhost:3306/TEST_DB
2020-08-04 19:09:31.093 DEBUG [main] [com.zaxxer.hikari.HikariConfig] leakDetectionThreshold..........0
2020-08-04 19:09:31.093 DEBUG [main] [com.zaxxer.hikari.HikariConfig] maxLifetime.....................120000
2020-08-04 19:09:31.093 DEBUG [main] [com.zaxxer.hikari.HikariConfig] maximumPoolSize.................30
2020-08-04 19:09:31.093 DEBUG [main] [com.zaxxer.hikari.HikariConfig] metricRegistry..................none
2020-08-04 19:09:31.093 DEBUG [main] [com.zaxxer.hikari.HikariConfig] metricsTrackerFactory...........none
2020-08-04 19:09:31.093 DEBUG [main] [com.zaxxer.hikari.HikariConfig] minimumIdle.....................1
2020-08-04 19:09:31.093 DEBUG [main] [com.zaxxer.hikari.HikariConfig] password........................<masked>
2020-08-04 19:09:31.093 DEBUG [main] [com.zaxxer.hikari.HikariConfig] poolName........................"chapuceros-pool"
2020-08-04 19:09:31.093 DEBUG [main] [com.zaxxer.hikari.HikariConfig] readOnly........................false
2020-08-04 19:09:31.093 DEBUG [main] [com.zaxxer.hikari.HikariConfig] registerMbeans..................false
2020-08-04 19:09:31.093 DEBUG [main] [com.zaxxer.hikari.HikariConfig] scheduledExecutor...............none
2020-08-04 19:09:31.093 DEBUG [main] [com.zaxxer.hikari.HikariConfig] scheduledExecutorService........internal
2020-08-04 19:09:31.093 DEBUG [main] [com.zaxxer.hikari.HikariConfig] schema..........................none
2020-08-04 19:09:31.093 DEBUG [main] [com.zaxxer.hikari.HikariConfig] threadFactory...................internal
2020-08-04 19:09:31.093 DEBUG [main] [com.zaxxer.hikari.HikariConfig] transactionIsolation............default
2020-08-04 19:09:31.093 DEBUG [main] [com.zaxxer.hikari.HikariConfig] username........................"defaultuser"
2020-08-04 19:09:31.093 DEBUG [main] [com.zaxxer.hikari.HikariConfig] validationTimeout...............5000
错误摘要:
[main] [com.zaxxer.hikari.HikariDataSource] chapuceros-pool - Starting...
[com.zaxxer.hikari.pool.PoolBase] chapuceros-pool - Failed to create/setup connection: Communications link failure
[com.zaxxer.hikari.pool.HikariPool] chapuceros-pool - Cannot acquire connection from data source
com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure
Caused by: java.net.SocketException: Broken pipe (Write failed)
将参数 ?useSSL=false
添加到 jdbcUrl
解决了我的问题。