无法从数据源获取连接(Hibernate + Hikari + MySQL)

huangapple go评论75阅读模式
英文:

Unable to acquire connection from data source(Hibernate + Hikari + MySQL)

问题

我正在尝试使用Hikari作为连接池连接到本地的MySQL数据库,但无法建立连接。

有人可以告诉我我做错了什么吗?

MySQL版本:
mysql Ver 8.0.21 for Linux on x86_64 (MySQL Community Server - 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.............&quot;/* ping */&quot;
...
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)
英文:

I'm trying to connect to a local MySql database using Hikari as the connection pool but I am unable to establish the connection.

Can someone tell me what I'm doing wrong?

MySql Version:
mysql Ver 8.0.21 for Linux on x86_64 (MySQL Community Server - GPL)

The dependencies in the project are as follows:

		&lt;dependency&gt;
			&lt;groupId&gt;org.hibernate&lt;/groupId&gt;
			&lt;artifactId&gt;hibernate-hikaricp&lt;/artifactId&gt;
			&lt;version&gt;5.3.6.Final&lt;/version&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;mysql&lt;/groupId&gt;
			&lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
			&lt;version&gt;8.0.21&lt;/version&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;com.zaxxer&lt;/groupId&gt;
			&lt;artifactId&gt;HikariCP&lt;/artifactId&gt;
			&lt;version&gt;2.7.6&lt;/version&gt;
		&lt;/dependency&gt;

HikariCP Startup log:

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.............&quot;/* ping */&quot;
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=&lt;masked&gt;, useLocalTransactionState=true}
2020-08-04 19:09:31.092 DEBUG [main] [com.zaxxer.hikari.HikariConfig] driverClassName.................&quot;com.mysql.cj.jdbc.Driver&quot;
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........................&lt;masked&gt;
2020-08-04 19:09:31.093 DEBUG [main] [com.zaxxer.hikari.HikariConfig] poolName........................&quot;chapuceros-pool&quot;
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........................&quot;defaultuser&quot;
2020-08-04 19:09:31.093 DEBUG [main] [com.zaxxer.hikari.HikariConfig] validationTimeout...............5000

Errors summary:

[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)

答案1

得分: 1

将参数?useSSL=false添加到jdbcUrl中解决了我的问题。

英文:

Adding the parameter ?useSSL=false to the jdbcUrl solved my problem.

huangapple
  • 本文由 发表于 2020年8月5日 06:35:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/63255980.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定