简体   繁体   English

2台笔记本电脑上的mysql通信链接失败

[英]mysql communication link failure on 2 laptops

I have made a software, I have made the mysql database on the different laptop, and the software on different laptop, means i have 2 laptops one has software and one has database and both are connected with internet wire. 我制作了一个软件,在另一个笔记本电脑上制作了mysql数据库,在另一个笔记本电脑上制作了该软件,这意味着我有2台笔记本电脑,其中一台具有软件,一台具有数据库,并且都通过互联网连接。 now I am connecting my software with the database which is installed on different laptop but I get a communication failure link. 现在,我将软件与安装在另一台笔记本电脑上的数据库连接起来,但出现通信故障链接。 I have given the ip address of the server laptop, but yet i get the error, please tell me how to resolve this issue, the code is here. 我已经给出了服务器笔记本电脑的IP地址,但是却出现错误,请告诉我如何解决此问题,代码在这里。

    private static void init()throws Exception{

    String url="jdbc:mysql://169.254.96.182:3306/content_management_system";
    String user="root";
    String password="oracle";

    con=DriverManager.getConnection(url, user, password);

    System.out.println("connection successfull");
}//end method

and the errror is 而错误是

 com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
    at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:989)
    at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:341)
    at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2189)
    at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2222)
    at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2017)
    at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:779)
    at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

By default, the port 3306; 默认情况下,端口3306; which you are using to route the connection to your database, will be closed - or at least, blocked from any outside connections. 用来将连接路由到数据库的数据库将被关闭-或至少被阻止与任何外部连接。

You'll need to open this port; 您需要打开此端口; and potentially add port forwarding to ensure any outside connections are directed properly. 并可能添加端口转发以确保正确定向任何外部连接。

Look up how to open ports and check out this link on port forwarding. 查找如何打开端口,并在端口转发中查看此链接

As mentioned in the comments you can also use the command PING 169.254.96.182 to check if a connection can be established! 如注释中所述,您还可以使用命令PING 169.254.96.182检查是否可以建立连接!

Also if you do open the port, unless you have strict security measures in place; 另外,如果您确实打开了端口,除非您采取了严格的安全措施; you should remove your IP from this question as you're basically giving us all access! 您应该从此问题中删除您的IP,因为您基本上是在为我们提供所有访问权限!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM