java - Spring Boot 无法在 mysql 上创建连接池

标签 java mysql spring-boot

我有一个 Spring Boot 应用程序,它在启动时抛出以下异常。奇怪的是同一个 jar(当从 Windows 和 Ubuntu 运行时)在 Windows 上与全新安装的 MySQL 5.7 一起工作,但在 Ubuntu 14 lts 上的 MySQL 5.6 上不起作用并抛出以下异常!

root权限,密码完全一样。我尝试在 Windows 和 Ubuntu 上全新安装 MySQL。在这一点上我一无所知——我已经尝试了类似于这个问题的答案的步骤,但没有任何效果。

这可能是 mysql 版本的问题?我可能错过了什么?

    EVERE: Unable to create initial connections of pool.
java.sql.SQLException: Access denied for user 'root'@'localhost' (using password                                                                                        : YES)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:963)
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3966)
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3902)
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:875)
        at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(My                                                                                        sqlIO.java:1712)
        at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1228)
        at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2253)
        at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2                                                                                        284)
        at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2083)
        at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:806)
        at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstruct                                                                                        orAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingC                                                                                        onstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
        at com.mysql.jdbc.Util.handleNewInstance(Util.java:404)
        at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:410)
        at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java                                                                                        :328)

最佳答案

MySQL 的错误信息是这部分:

Access denied for user 'root'@'localhost' (using password: YES)

当用户/主机不存在或具有不同的密码(或在不需要密码时提供密码)时,这是一条标准错误消息。适用于该 MySQL 错误的标准故障排除。该 MySQL 错误表明问题所在。

你声称“root权限,密码完全一样”。

如果是这样,则连接池的配置有所不同。

我会检查 mysql.user 表中“用户”、“主机”和“密码”列的值。还要验证插件列是否包含 'mysql_native_password'

是否有值 'root''localhost' 的行? (MySQL 中的用户由“User”和“Host”的组合来标识。)

该用户的密码哈希是否匹配? (将查询返回的散列与存储在 mysql.user 表中的散列进行比较……SELECT PASSWORD('mysupersecret'))

如果使用 DML 操作对 mysql.user 表进行了更改,是否执行了 FLUSH PRIVILEGES 语句以强制 MySQL 服务器重新读取授权表?

这些只是一些指南。提供的信息不足,无法准确诊断问题。


https://dev.mysql.com/doc/refman/5.7/en/problems-connecting.html

A very common error is to insert a new row with Host='%' and User='some_user', thinking that this enables you to specify localhost to connect from the same machine. The reason that this does not work is that the default privileges include a row with Host='localhost' and User=''. Because that row has a Host value 'localhost' that is more specific than '%', it is used in preference to the new row when connecting from localhost! The correct procedure is to insert a second row with Host='localhost' and User='some_user', or to delete the row with Host='localhost' and User=''. After deleting the row, remember to issue a FLUSH PRIVILEGES statement to reload the grant tables.


我强烈建议您考虑为您的应用程序创建 other 用户,并遵循 最小权限 的最佳实践安全原则。

关于java - Spring Boot 无法在 mysql 上创建连接池,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40295067/

相关文章:

mysql - 有没有办法计算 first_check_in 和 last_check_out 之间的总休息时间?

mysql - mysql中如何计算权重

mysql - 如何为数据库的特定表生成 liquibase changelog xml

java - 从文件系统中的任何位置使用 Spring-Boot 和 Spring-MVC 提供文件服务

Java Web应用快速开发工具——元数据驱动

java - 如何在 AppCompatButton 旋转时更改其背景?

JAVA - 数组越界错误

c# - 如何像在 C# 中一样在 Java 中使用委托(delegate)?

java - SpringBoot SpringApplicationBuilder

spring-boot - Spring boot - 如何使用故障转移 URL 连接到外部 ActiveMQ 主/从集群