gpt4 book ai didi

java - mySQL远程数据库无法连接

转载 作者:行者123 更新时间:2023-11-29 21:26:08 25 4
gpt4 key购买 nike

我有什么遗漏的吗?我的远程 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.");

它告诉我访问被拒绝。

这是堆栈跟踪:

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)

最佳答案

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

举个例子,如果你 telnet google @ 端口 80:

远程登录8.8.8.8 80

您将看到此回复:

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

当您 telnet 远程 IP 时,应该会观察到类似的结果。如果不是,则该端口未在 Google Cloud 上打开,或者您的 ISP 提供商阻止了端口 3306 的传出流量。

关于java - mySQL远程数据库无法连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35509813/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com