无法从外部IPV4地址连接到MySQL服务器



我的Java应用程序出现问题已经有一段时间了。我尝试了几个选项,试图找出问题所在,从新的驱动程序到注册驱动程序,再到更改MySQL数据库的权限。只有当我连接到外部IP时,我才会遇到这个问题。我认为这可能与IPV6有关,但我曾试图在我的树莓派上禁用它,但当我运行"netstat-tlnp"时,我得到了这个:

(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 127.0.0.1:8005          0.0.0.0:*               LISTEN      547/java            
tcp        0      0 0.0.0.0:8200            0.0.0.0:*               LISTEN      547/java            
tcp        0      0 0.0.0.0:8009            0.0.0.0:*               LISTEN      547/java            
tcp        0      0 0.0.0.0:5900            0.0.0.0:*               LISTEN      -                   
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      -                   
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      -                   
tcp6       0      0 :::5900                 :::*                    LISTEN      -                   
tcp6       0      0 :::8080                 :::*                    LISTEN      -                   
tcp6       0      0 :::22                   :::*                    LISTEN 

这表明MySQL服务器仍在运行tcp6,端口为8080,我将其从标准3600更改为8080。我的java主类如下:`public static String IP//MySQL服务器IP的NULL变量public static final字符串user="user"//mySQL服务器的用户名public static final字符串password="pass"//mySQL服务器的密码TODO找出如何隐藏密码静态连接连接//NULL连接以连接到mySQL服务器公共静态扫描仪控制台=新扫描仪(System.in(//用于从控制台获取数字和字符串

/**
* Runs the program
* @param args
*/
public static void main(String[] args) {
System.out.print("Internal or External IP (1 for Internal or 2 for external): ");
int choice = console.nextInt();
switch (choice){
case 1:
IP = "10.0.0.183";
break;
case 2:
IP = "external ipv4 address";
break;
}
//TRY CATCH method to ensure that the mySQL connection was successful
try{
conn = DriverManager.getConnection("jdbc:mysql://"+IP+":8080/mydb",user,password);
}catch(SQLException e){
System.out.println(e.getLocalizedMessage());
System.exit(1);
}`

这是我尝试连接到外部IPV4地址时遇到的错误`Communications link failure

最后一个成功发送到服务器的数据包是0毫秒前。驱动程序没有从服务器接收到任何数据包

有人有解决方案或需要我提供其他帮助来解决这个问题吗!谢谢

您是否使用这个10.0.0.183创建了MySQL用户?请使用此创建MySQL用户,并提供授权并检查

相关内容

最新更新