无法连接到MySQL数据库

时间:2015-05-26 11:09:05

标签: java mysql sql

每次尝试运行此rs私有服务器时,都会出现此控制台错误。几乎所有东西都连接到一个mysql db。

我一直在讨论这个问题很长一段时间,但是无法弄清楚什么是错的。如果有任何特定的文件你可能需要查看以帮助我弄清楚什么是错的,告诉我,我会发布它。

所有帮助都将受到高度赞赏!

[Stage - 1] Launching Elunity...
[Stage - 2] Loaded object configurations
[Stage - 3] Loaded region configurations
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet successfully received from the server was 1 432 637 479 787 milliseconds ago.  The last packet sent successfully to the   server was 0 milliseconds ago.
Failed to connect to MySQL database
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:406)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2214)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:773)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:46)
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:406)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:352)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:282)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at paladious.model.players.Highscores.process(Highscores.java:17)
at paladious.Server.main(Server.java:117)
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet successfully received from the server was 1 432 637 479 777 milliseconds ago.  The last packet sent successfully to the server was 0 milliseconds ago.
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:406)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:341)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2137)
... 13 more
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:253)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:290)
... 14 more
[Stage - 4] Loaded single event manager
[Stage - 7] Loaded NPC drops
[Stage - 8] Loaded player punishments and starters
[Stage - 10] Elunity online on port :43594

提前致谢! :)

1 个答案:

答案 0 :(得分:0)

这是一个包装的例外,并不是很有趣。它是异常的根本原因,它实际上告诉我们一些根本原因。请在堆栈跟踪中进一步了解一下。您将面临SQLException的可能性很大:连接被拒绝或SQLException:连接超时。

如果你的情况也是如此,那么所有可能的原因都是:

  1. JDBC URL中的IP地址或主机名错误。
  2. 本地DNS服务器无法识别JDBC URL中的主机名。
  3. JDBC URL中缺少或错误端口号。
  4. 数据库服务器已关闭。
  5. 数据库服务器不接受TCP / IP连接。
  6. Java和DB之间的某些东西阻止了连接,例如防火墙或代理。
  7. 要解决其中一个问题,请遵循以下建议:

    1. 使用ping验证并测试它们。
    2. 刷新DNS或在JDBC URL中使用IP地址。
    3. 根据MySQL DB的my.cnf进行验证。
    4. 启动它。
    5. 验证mysqld是否在没有--skip-networking选项的情况下启动。
    6. 禁用防火墙和/或配置防火墙/代理以允许/转发 港口。