database 如何从另一台计算机连接到本地主机
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/14641107/
Warning: these are provided under cc-by-sa 4.0 license.  You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to connect to localhost from another computer
提问by aratn0n
I make database program and use localhost as host. I want my friend to test my program but I don't know how to connect from another computer.
我制作数据库程序并使用 localhost 作为主机。我想让我的朋友测试我的程序,但我不知道如何从另一台计算机连接。
PS. I use windows 7 and MySql.
附注。我使用 Windows 7 和 MySql。
回答by paxdiablo
localhostis just an alias for the loopback address 127.0.0.1, which means this computer.
localhost只是环回地址 127.0.0.1 的别名,意思是这台电脑。
If you want to communicate with that computer from somewhere else,you'll need to use its real IP address.
如果您想从其他地方与该计算机通信,则需要使用其真实 IP 地址。
For example, see the following "diagram" showing where connectons will go depending on the IP address used:
例如,请参阅以下“图表”,其中显示了连接将根据所使用的 IP 地址进行的位置:
    +-----------+ 10.1.1.8 +-----------+
    | MyPC      | <------- | YourPC    |
    |           |          |           |
    | 10.1.1.8  | -------> | 10.1.1.9  |
    +-----------+ 10.1.1.9 +-----------+
      |       ^              |       ^
      |       |              |       |
    127.0.0.1-+            127.0.0.1-+
With Windows, you should be able to get your IP address with ipconfig(ifconfigunder most UNIX-type systems) and just plug that into your connection parameters where you currently have localhost.
在 Windows 中,您应该能够使用ipconfig(ifconfig在大多数 UNIX 类型系统下)获取您的 IP 地址,并将其插入您当前拥有的连接参数中localhost。
Keep in mind that you may still need to grant power to the remote IP address to connect, such as with (assuming you're trying to connect from 10.1.1.8):
请记住,您可能仍需要为远程 IP 地址授予电源以进行连接,例如使用(假设您尝试从 连接10.1.1.8):
GRANT ALL PRIVILEGES ON *.* TO 'mysql'@'10.1.1.8' IDENTIFIED BY 'super-sekrit'
回答by Hanky Panky
Are both the computers on same network? Then just provide your LAN ip address to your friend. However if you are on internet and not behind a NAT firewall then you can provide him your public ip addres. If you are behind a NAT router then you have to setup port forwarding on your router
两台电脑在同一个网络上吗?然后只需将您的 LAN ip 地址提供给您的朋友。但是,如果您在互联网上并且不在 NAT 防火墙后面,那么您可以向他提供您的公共 IP 地址。如果您在 NAT 路由器后面,则必须在路由器上设置端口转发
回答by spiritwalker
you mean connect to your program or your DB? you can replace your "localhost" with IP address to make your program accessible from another computer.
你的意思是连接到你的程序或你的数据库?您可以将“localhost”替换为 IP 地址,以便从另一台计算机访问您的程序。
回答by Shurmajee
Localhost is the standard hostname given to the address of the loopback network interface. for communication between two computers :
Localhost 是指定给环回网络接口地址的标准主机名。用于两台计算机之间的通信:
- Use your systems IP address.
- first make sure that your system can be pinged from your friends PC.
- make sure the corresponding port that your application listens on is open.
- 使用您的系统 IP 地址。
- 首先确保您的系统可以从您朋友的 PC 上 ping 通。
- 确保您的应用程序侦听的相应端口已打开。

