简体   繁体   English

无法使用外部IP地址连接到MySQL数据库

[英]can't connect to MySQL database using external ip address

I have a MySQL server running on my Windows 7 computer as a Windows Service. 我有一个作为Windows服务在Windows 7计算机上运行的MySQL服务器。 When I try to connect to it using external.ip = my ip address from http://www.whatismyip.com/ in command prompt: 当我尝试使用external.ip =我的IP地址从http://www.whatismyip.com/在命令提示符下连接到它时:

mysql -h external.ip -u root -p

it returns: 它返回:

ERROR 2003 (HY000): Can't connect to MySQL server on external.ip (10060)

I can, however, connect it to it when I change external.ip to the ip address listed with the ipconfig command: 但是,当我将external.ip更改为ipconfig命令列出的ip地址时,可以将其连接到它:

mysql -h ipconfig.ip -u root -p

I already changed the permissions for root to accept any host (using commands like those from Accessing a mysql database from external host/ip? (ie: mysql workbench) ). 我已经更改了root的权限以接受任何主机(使用类似从外部host / ip?访问mysql数据库中的命令(即:mysql workbench)中的命令 )。 In the database: 在数据库中:

SELECT host, user FROM user;

returns (to summarize): 回报(总结):

| host   | user |
-----------------
| %      | root |

Also, in my my.ini file, there is no line that says skip-networking. 另外,在my.ini文件中,没有任何行显示跳过网络。

It worked fine when I tried this the other day on a different network where external.ip was the same as ipconfig.ip . 前几天当我在external.ipipconfig.ip相同的另一个网络上尝试此操作时,它工作正常。 Could this be the source of the problem or is there something else? 这可能是问题的根源,还是还有其他问题?

If http://www.whatismyip.com/ and the address you get from ipconfig are different, that means you're using a local router (probably the one you use to connect to the internet) that network address translation. 如果http://www.whatismyip.com/与您从ipconfig获得的地址不同,则意味着您正在使用本地路由器(可能是用于连接到Internet的路由器)进行网络地址转换。 In other words, you have a local network (in your house or your fav internet cafe) that has private-network addresses like 192.168.0.1 or 10.0.0.1. 换句话说,您有一个本地网络(在您的房子或您最喜欢的网吧中),该局域网具有诸如192.168.0.1或10.0.0.1。的专用网络地址。

MySQL usually uses listens on port 3306 for inbound connection requests. MySQL通常在端口3306上使用侦听来进行入站连接请求。 But, when you try to connect via your public ip address (the What's My IP address) your network provider sends the request to your router. 但是,当您尝试通过公用ip地址(“我的IP地址”)进行连接时,网络提供商会将请求发送到路由器。 The router notices port 3306, but it probably doesn't know what to do with it. 路由器会注意到端口3306,但它可能不知道该如何处理。 So it silently ignores the request. 因此,它默默地忽略了该请求。 The software you're using to make the connection then times out. 您用来建立连接的软件会超时。 This is good. 很好 Crackers try to connect to ports like that to see if they can get into your machine. 饼干试图连接到这样的端口,以查看它们是否可以进入您的计算机。

So, to get this to work you need to configure your router to pass incoming TCP requests to port 3306 through to the machine that runs your MySQL server. 因此,要使其正常工作,您需要配置路由器,以将传入的TCP请求通过端口3306传递到运行MySQL服务器的计算机。 It probably has a configuration screen to do this. 它可能具有配置屏幕来执行此操作。 It will work on the router you own. 它将在您拥有的路由器上工作。 It won't work on the coffee shop router. 它不能在咖啡厅路由器上工作。

If you're not sure what "port" means, or why you get a different IP address from ipconfig and from http://www.whatismyip.com/ , with respect you probably need to learn quite a bit more about internet technology before you should attempt this kind of thing. 如果您不确定“端口”是什么意思,或者不确定为什么从ipconfig和http://www.whatismyip.com/获得不同的IP地址,那么您可能需要先了解很多有关互联网技术的知识您应该尝试这种事情。

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

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