【发布时间】:2015-06-21 12:38:11
【问题描述】:
我正在尝试从 java 连接到数据库并收到以下错误消息:
java.sql.SQLException: Access denied for user 'gda'@'localhost' (using password: YES)
但我正在连接的命令行使用相同的凭据
server$ mysql -ugda -pgda
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2666453
Server version: 5.5.39-36.0-log Percona Server (GPL), Release 36.0, Revision 697
Copyright (c) 2009-2014 Percona LLC and/or its affiliates
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
在另一个数据库上,我的 java 工作正常并且能够连接。似乎是数据库级别的问题?!我需要在数据库级别修复什么?
添加连接代码:
public Connection getConnection() {
try {
Class.forName(jdbcDriver);
connection = DriverManager.getConnection(connectionString());
}
catch(Exception ex) {
ex.printStackTrace();
logger.error("Exception:" + ex.getMessage());
errorMessage = ex.getMessage();
}
return connection;
}
地点:
jdbc:mysql://127.0.0.1:3306/db?user=gda&password=gda
【问题讨论】:
-
你能显示连接的代码吗?
-
我不知道我从我们的 dba 那里得到了这个凭据,我猜他更改了 root 密码
-
也许它可以帮助(类似问题)这里stackoverflow.com/questions/28954740/…
-
我遇到了那个错误,我使用的密码不正确
-
我遇到了类似的问题,但使用的是 php。不要使用
localhost,而是尝试使用127.0.0.1,这对我有用。