Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从java到mysql的连接被拒绝访问_Java_Mysql - Fatal编程技术网

从java到mysql的连接被拒绝访问

从java到mysql的连接被拒绝访问,java,mysql,Java,Mysql,我正在尝试从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 26664

我正在尝试从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

尝试以以下方式传递用户名和密码:

String DB_URL = "jdbc:mysql://localhost/xyz";
String USER = "username";
String PASS = "password";

conn = DriverManager.getConnection(DB_URL,USER,PASS);

你能显示连接的代码吗?我不知道我从我们的dba那里得到了这个凭证,我想他更改了根密码也许这可以帮助解决类似的问题这里我有一个错误,我使用了一个不正确的密码我有一个类似的问题,但与php有关。不要使用localhost,而是尝试使用127.0.0.1,这对我来说很有效。我怀疑这是否能解决问题,也许它应该作为注释发布?如果不能解决这个问题,我认为值得一试。尝试过但不起作用,我创建了一个新用户,并且能够使用旧java代码进行连接。所以,数据库级别的用户有问题。我向我们的dba提出了这个问题