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