简体   繁体   English

java.sql.SQLException(使用密码:NO)

[英]java.sql.SQLException (using password: NO)

I'm attempting to connect to my server's MySQL, yet I keep running into the same issue and cannot find a similar problem. 我正在尝试连接到服务器的MySQL,但是仍然遇到相同的问题,但是找不到类似的问题。 My code snippet is below: 我的代码段如下:

public class MySqlDatabaseHandler {
    Connection con = null;
    Statement st = null;
    ResultSet rs = null;

    public MySqlDatabaseHandler(String url, String user, String password){
        /*String url = "jdbc:mysql://192.168.1.80:3306/testdb";
        String user = "root";
        String password = "rootpass";*/
        try {
            Class.forName("com.mysql.jdbc.Driver");
            con = DriverManager.getConnection(url, user, password);
            st = con.createStatement();
        }
        catch (Exception e){
            e.printStackTrace();
        }  
    }
}

And the results I receive: 我收到的结果是:

java.sql.SQLException: Access denied for user 'root'@'192.168.1.3' (using password: NO)
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(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:404)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:317)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at handleServer.includes.classes.Server.MySqlDatabaseHandler.<init>(MySqlDatabaseHandler.java:24)

By the look of things, I believe the password is never being sent to the server because of the "(using password: NO)". 从外观上看,我相信由于“(使用密码:否)”,该密码从未被发送到服务器。

I have even attempted to change the url to "jdbc:mysql://192.168.1.80:3306/testdb?user=root&password=rootpass" and find myself with the same results. 我什至尝试将URL更改为“ jdbc:mysql://192.168.1.80:3306 / testdb?user = root&password = rootpass”,并发现自己的结果相同。

MySql allows remote connection to the testing client(192.168.1.3) and has been tested with telnet, but runs into this issue with JDBC. MySql允许远程连接到测试客户端(192.168.1.3),并且已经使用telnet进行了测试,但是使用JDBC时遇到了此问题。 Does anyone see what I am doing wrong? 有人看到我在做什么错吗?

It seems something is wrong with MySQL privilege setting.You can try this,open MySQL command line prompt,run the following script: MySQL权限设置似乎有问题。您可以尝试执行此操作,打开MySQL命令行提示符,运行以下脚本:

grant all privileges on *.* to 'root'@'localhost' identified by 'password' with grant option;
flush privileges;

I think this is a purposeful limitation to prevent root access on a network. 我认为这是有目的的限制,以防止在网络上进行根访问。 Try taking a look at this Q&A for the workaround. 尝试查看此问答以了解解决方法。 It's basically the same as @pigletfly's solution but with a domain name. 它与@pigletfly的解决方案基本相同,但是具有域名。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.sql.SQLException:访问被拒绝用户''@'localhost'(使用密码:否) - java.sql.SQLException: Access denied for user ''@'localhost' (using password: NO) 渗透:java.sql.SQLException:对用户&#39;root&#39;@&#39;localhost&#39;的访问被拒绝(使用密码:是)。 如何不使用密码? - Osmosis: java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES). How not to use a password? java.sql.SQLException:使用属性文件的用户“java”'@'localhost'(使用密码:YES)拒绝访问 - java.sql.SQLException: Access denied for user '“java”'@'localhost' (using password: YES) using properties file java.sql.SQLException:在春季使用mysql拒绝用户&#39;root&#39;@&#39;localhost&#39;(使用密码:YES)的访问 - java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES) in spring using mysql java.sql.SQLException:用户&#39;userx&#39;@&#39;%&#39;的访问被拒绝(使用密码:是) - java.sql.SQLException: Access denied for user 'userx'@'%' (using password: YES) java.sql.SQLEXCEPTION:用户“root”@“localhhost”的访问被拒绝(使用密码:是) - java.sql.SQLEXCEPTION: Access denied for user 'root'@'localhhost' (using password: YES) 一个旧的Q,但对我来说还没有解决方案:java.sql.SQLException:用户&#39;root&#39;@&#39;localhost&#39;的访问被拒绝(使用密码:NO) - An old Q but no solution for me yet: java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: NO) java.sql.SQLException:用户&#39;TMing&#39;@&#39;localhost&#39;的访问被拒绝(使用密码:是) - java.sql.SQLException: Access denied for user 'TMing'@'localhost' (using password: YES) java.sql.SQLException:用户&#39;root&#39;@&#39;172.17.0.1&#39;的访问被拒绝(使用密码:是) - java.sql.SQLException: Access denied for user 'root'@'172.17.0.1' (using password: YES) java.sql.SQLException:访问被拒绝用户'root'@'localhost'(使用密码:是) - java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM