【问题标题】:Unable to create initial pool of connections in springboot无法在 Spring Boot 中创建初始连接池
【发布时间】:2019-06-08 05:37:52
【问题描述】:

我正在尝试使用 springboot 连接数据库,但它没有以任何方式运行。到目前为止,我已经提出了大约 3 个应用程序,但都有相同的问题。我是一个春天的新手,第一次工作。

我在应用程序中使用了 JPA 和 Mysql,但始终会出现错误。

申请文件

  datasource:
    url: jdbc:mysql://localhost:3306/test_schema
    username: root
    password: user
  jpa:

    generate-ddl: true
    show-sql: true

错误

Sat Jun 08 11:02:13 IST 2019 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
2019-06-08 11:02:13.362 ERROR 14040 --- [           main] o.a.tomcat.jdbc.pool.ConnectionPool      : Unable to create initial connections of pool.

java.sql.SQLException: Unable to load authentication plugin 'caching_sha2_password'.
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:868) ~[mysql-connector-java-5.1.41.jar:5.1.41]
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:864) ~[mysql-connector-java-5.1.41.jar:5.1.41]
    at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1746) ~[mysql-connector-java-5.1.41.jar:5.1.41]
    at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1226) ~[mysql-connector-java-5.1.41.jar:5.1.41]
    at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2205) ~[mysql-connector-java-5.1.41.jar:5.1.41]
    at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2236) ~[mysql-connecto......

Error continues and is really a very long list

我之前问过一个类似的问题,但解决了数据库模式和表的问题,但现在出现了。几乎所有应用程序都显示此错误。 Mysql 已启动并正在运行。用户名密码正确。数据库也有一些初始条目。

【问题讨论】:

  • 你能登录mysql吗?mysql -uroot -pusertelnet 127.0.0.1 3306端口是否开放?需要更多信息。
  • @jin 是打开的。顺便说一句,下面的答案解决了上述错误,但现在出现了一个新错误。 java.sql.SQLException: 未知系统变量 'query_cache_size'

标签: java mysql spring spring-boot jpa


【解决方案1】:

caching_sha2_password 是 MySQL 的默认身份验证插件。 请尝试更新 mysql 连接器库以说 mysql-connector-java-8.0.12 (尝试匹配 mysql 版本和连接器版本) 可能你正在使用“5.1.44”左右的版本。

另外,如果这不起作用,请按照上面的建议尝试

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'user';

如果更改修复了这个问题但导致了不同的异常:java.sql.SQLException: Unknown system variable 'query_cache_size',它可能表明 mySQL 连接器的版本不正确/不匹配MySQL 8x 版本

请记住,“查询缓存自 MySQL 5.7.20 起已弃用,并在 MySQL 8.0 中被删除”

更新 MYSQL 连接器库的依赖项以使用更高版本,最新日期为 8.0.15:

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>8.0.15</version>
</dependency>

【讨论】:

  • 这适用于上述错误,但现在发生了一个新错误:java.sql.SQLException: Unknown system variable 'query_cache_size'
  • 请尝试根据更新后的答案更新 mysql 连接器版本。
【解决方案2】:

在你的mysql服务器上运行这个命令:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'user';

【讨论】:

  • 这对上述错误有效,但现在出现了一个新错误:java.sql.SQLException: Unknown system variable 'query_cache_size'
猜你喜欢
  • 2018-10-23
  • 2017-02-02
  • 2019-10-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-06-19
  • 1970-01-01
  • 2018-08-08
相关资源
最近更新 更多