有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java mySQL远程数据库未连接

我有什么遗漏吗? 我的远程MySQL数据库位于谷歌云上,我允许访问我当前的外部IP:

String myDriver = "org.gjt.mm.mysql.Driver";
String myURL = "jdbc:mysql://<remote IP address here>:3306/test";
System.setProperty("useSSL", "true");
System.setProperty("user", "test");
System.setProperty("password", "test");
System.setProperty("javax.net.ssl.keyStore","lib\\keystore");
System.setProperty("javax.net.ssl.keyStorePassword","password here");
System.setProperty("javax.net.ssl.trustStore","lib\\truststore");
System.setProperty("javax.net.ssl.trustStorePassword","password here");
Class.forName(myDriver);
connection = DriverManager.getConnection(myURL, System.getProperties());
System.out.println("Connection successful.");

它告诉我访问被拒绝

以下是stacktrace:

Access denied for user 'test'@'my external IP' (using password: YES)
java.sql.SQLException: Access denied for user 'test'@'my external IP' (using password: NO)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:957)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3878)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3814)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:871)
at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1694)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1215)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2255)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2286)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2085)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:795)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:44)
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:404)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:400)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:327)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at Test.main(Test.java:16)

共 (1) 个答案

  1. # 1 楼答案

    检查是否可以使用以下命令远程登录ip地址。 telnet远程ip端口

    例如,如果u telnet google@port 80:

    telnet 8.8.8.80

    你会看到这样的反应:

    尝试8.8.8.8。。。 连接到8.8.8.8。 转义字符为“^]”

    当使用telnet远程ip时,也应该观察到类似的结果。如果没有,要么该端口在google cloud没有打开,要么您的ISP提供商正在阻止@port 3306的传出流量