6

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.

PS. I use windows 7 and MySql.

aratn0n
  • 553
  • 3
  • 5
  • 17
  • 1
    have you tried anything yet ? – Manoj Purohit Feb 01 '13 at 06:48
  • possible duplicate of [How do I connect to this localhost from another computer on the same network?](http://stackoverflow.com/questions/9682262/how-do-i-connect-to-this-localhost-from-another-computer-on-the-same-network) – Mick Jul 30 '13 at 14:56

4 Answers4

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'
paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953
  • I can get my ip by type ipconfig in cmd and put my ip in connection string (SERVER = my ip) ,right? – aratn0n Feb 01 '13 at 06:50
  • @aratn0n, yes, do that on the machine where the server is running then configure the other machine to use that setting. – paxdiablo Feb 01 '13 at 06:54
  • I change connection parameter to my IP address when I start program It say host 'my IP' is not allowed to connect to this MySql server – aratn0n Feb 01 '13 at 07:02
  • @aratn0n, that's a different issue, possibly requiring configuration of your SQL server or firewalls, etc. See http://stackoverflow.com/questions/5915534/accessing-a-mysql-database-from-external-host-ip-ie-mysql-workbench for example, where you need to grant privs to the remote IP address (the one you're using to connect to the server). I'll update the answer. – paxdiablo Feb 01 '13 at 07:36
  • Adding to paxdiablo's points, is your friend on the same network as you or in a different location? If you're behind a router that creates an internal subnet for you (192.168.1.x is common) you'll need to provide your public IP address to him. Google "what is my ip" and it tells you. – Grambot Feb 13 '13 at 13:53
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

Hanky Panky
  • 46,730
  • 8
  • 72
  • 95
  • 1
    We use same internet (WiFi) in university but different place and connection. Will it be the same connection ? – aratn0n Feb 01 '13 at 06:54
  • 1
    yes. Check for your ip under networks and connections and then check for his. Also you can run `cmd` and then run `ipconfig`. It will tell you your ip address. Just give that to your friend to attempt a connection on. Since you use same WiFi router it should not be a big problem – Hanky Panky Feb 01 '13 at 06:56
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.

spiritwalker
  • 2,257
  • 14
  • 9
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.
Shurmajee
  • 1,027
  • 3
  • 12
  • 35