Java JDBC:MySQLNonTransientConnectionException尝试连接IP地址时

时间:2017-10-07 01:38:24

标签: java mysql jdbc

如果我这样做:

Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/imageusers?autoReconnect=true&useSSL=false&relaxAutoCommit=true", "username", "password");

然后它完全正常,但如果我这样做:

Connection myConn = DriverManager.getConnection("jdbc:mysql://IP:3306/imageusers?autoReconnect=true&useSSL=false&relaxAutoCommit=true", "username", "password");

然后它给了我一长串错误:

com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

我从这个网站获得了我的IP地址:http://whatismyipaddress.com/ 并在另一个查找器上双重检查它是相同的所以我不认为我在IP地址错误。我也对Windows防火墙中的端口3306做了一个例外,并检查了MySQL是否在Windows中的服务应用程序中运行。我打开并运行MySQL程序的东西。我不知道还能做什么。

1 个答案:

答案 0 :(得分:0)

您在此提供的是公共IP。它不会将其转换为私有IP地址。尝试从连接到数据库服务器的计算机ping公共IP。它也行不通。我建议你使用私人IP地址。