gpt4 book ai didi

java - SQLException : Access denied for user 'whatever' @'localhost'

转载 作者:行者123 更新时间:2023-11-29 19:11:11 25 4
gpt4 key购买 nike

凭据正确,数据库名称正确,MySQL 用户设置正确并拥有所有权限,我有“用户名”@“%”和“用户名”@“localhost”条目,我可以连接到此用户可以正确通过命令行以及通过 mysql 工作台。换句话说,一切都按其应有的方式工作并按其应有的方式设置,除了我的 java 应用程序无法连接。

我做了大约3次干净的卸载和安装MySQL,重新启动,没有重新启动,尝试通过应用程序以root身份(通过pass)登录,但这不起作用,尝试通过应用程序作为没有密码的用户登录(相同的错误)等

此外,使用完全相同的登录名在本地主机上运行的 PHP 网站也可以完美运行。

在过去的三天里,我一直在检查、重新检查和尝试所有这些,我浏览了所有相关的 SO 问题、我能找到的所有博客和文档,所有这些。

try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://localhost/correctDBname", "correctUsername", "correctPassword");
} catch(ClassNotFoundException | SQLException ex) {
Logger.getLogger(SqlConnection.class.getName()).log(Level.SEVERE, ex.getMessage(), ex);
}

MySQL 驱动程序名称与项目中 NetBeans 的“库”部分中显示的名称完全相同:MySQL JDBC 驱动程序 - mysql-connector-java-5.1.23-bin.jar

异常的全文:

java.sql.SQLException: Access denied for user 'strada'@'localhost' (using password: YES)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1074)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4120)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4052)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:925)
at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1704)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1250)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2465)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2498)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2283)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:822)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:404)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:317)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at eu.storemedia.stradaserver.engine.SqlConnection.<init>(SqlConnection.java:23)
at eu.storemedia.stradaserver.engine.StradaServer.<init>(StradaServer.java:51)
at eu.storemedia.stradaserver.Home.<clinit>(Home.java:31)

最佳答案

我建议您仔细阅读 MySQL 手册中有关连接故障排除的部分中的每一条建议。

另外,请检查 Connector/J 故障排除页面:

后一页包含这个有用的提示:

Note: Testing your connectivity with the mysql command-line client will not work unless you add the "host" flag, and use something other than localhost for the host. The mysql command-line client will use Unix domain sockets if you use the special host name localhost. If you are testing connectivity to localhost, use 127.0.0.1 as the host name instead.

这表明...实际上...您可能没有检查 JDBC 驱动程序正在使用的实际连接方法。它可能会对身份验证产生影响。

关于java - SQLException : Access denied for user 'whatever' @'localhost' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43071975/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com