mySQL远程数据库未连接

时间:2016-02-19 16:14:05

标签: java mysql jdbc google-cloud-platform

我有什么遗失的吗? 我的远程MySQL数据库在Google Cloud上,我可以访问我当前的外部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 个答案:

答案 0 :(得分:0)

使用以下命令检查是否可以telnet ip地址。 telnet remote-ip port。

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

telnet 8.8.8.8 80

你会看到这个回应:

尝试8.8.8.8 ...... 连接到8.8.8.8。 逃脱角色是&#39; ^]&#39;。

当你使用telnet remote-ip时,应该观察到类似的结果。如果没有该端口未在谷歌云端打开,或者您的ISP提供商阻止了传出流量@端口3306。