can't connect to MySQL database using external ip address

不问归期 提交于 2019-12-07 18:59:15

问题


I have a MySQL server running on my Windows 7 computer as a Windows Service. When I try to connect to it using external.ip = my ip address from http://www.whatismyip.com/ in command prompt:

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:

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)). 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.

It worked fine when I tried this the other day on a different network where external.ip was the same as ipconfig.ip. Could this be the source of the problem or is there something else?


回答1:


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. 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.

MySQL usually uses listens on port 3306 for inbound connection requests. 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. The router notices port 3306, but it probably doesn't know what to do with it. 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. 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.



来源:https://stackoverflow.com/questions/17155665/cant-connect-to-mysql-database-using-external-ip-address

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!