6

我制作数据库程序并使用 localhost 作为主机。我想让我的朋友测试我的程序,但我不知道如何从另一台计算机连接。

PS。我使用 Windows 7 和 MySql。

4

4 回答 4

7

localhost is just an alias for the loopback address 127.0.0.1, which means this computer.

If you want to communicate with that computer from somewhere else, you'll need to use its real IP address.

For example, see the following "diagram" showing where connectons will go depending on the IP address used:

    +-----------+ 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 (ifconfig under most UNIX-type systems) and just plug that into your connection parameters where you currently have 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):

GRANT ALL PRIVILEGES ON *.* TO 'mysql'@'10.1.1.8' IDENTIFIED BY 'super-sekrit'
于 2013-02-01T06:48:05.633 回答
2

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

于 2013-02-01T06:48:41.403 回答
1

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.

于 2013-02-01T06:48:07.317 回答
0

Localhost is the standard hostname given to the address of the loopback network interface. for communication between two computers :

  • 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.
于 2013-02-01T06:49:45.443 回答