gpt4 book ai didi

java - Java中的Mysql连接: Access denied for user @ localhost

转载 作者:行者123 更新时间:2023-11-29 13:08:12 24 4
gpt4 key购买 nike

我无法连接到数据库,但我不知道为什么,因为用户名和密码是正确的,并且我可以在本地通过 phpmyadmin 连接。

  Class.forName("com.mysql.jdbc.Driver");
// Setup the connection with the DB
connect = DriverManager.getConnection(
"jdbc:mysql://localhost/yerobot", "yerobot", "yerobot123");

preparedStatement = connect.prepareStatement("select * from userdata");

resultSet = preparedStatement.executeQuery();
while(resultSet.next()){
// do read rs
}

每当我调用连接时,我都会得到这个堆栈跟踪:

java.sql.SQLException: Access denied for user 'yerobot'@'localhost' (using password: YES)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1086)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4237)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4169)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:928)
at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1750)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1290)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2502)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2535)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2320)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:834)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:46)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:416)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:347)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at yerobot.MySQLAccess.setZockerzaster(MySQLAccess.java:92)
at yerobot.MyBot.zasterAction(MyBot.java:102)
at yerobot.MyBot$1.run(MyBot.java:94)
at java.util.TimerThread.mainLoop(Unknown Source)
at java.util.TimerThread.run(Unknown Source)

最佳答案

您需要为 yerobot@localhost 和 yerobot@'%' 设置密码

MySQL区分本地访问和远程访问密码。

关于java - Java中的Mysql连接: Access denied for user @ localhost,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22418027/

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