Skip to content Skip to sidebar Skip to footer

Can't Connect To Mysql From Android Device

On my tablet, I am using a simple app from android app store to access mysql database on my PC (mysql manager). It fails saying: error.communication failure. The last packet suc

Solution 1:

Solution Intranet/Lan (probably wi-fi):

If your Android Device is on LAN NetWork (probably wi-fi), you have to use the "lan ip".

  1. Get the ip (local ip/lan ip) of your PC (something like 192.168.1.101 or 10.0.0.101 or 10.1.1.12)
  2. In your App (on android device) access something like 192.168.1.101:3306
  3. Tip: recommend setting (manually) the IP of your computer because the router wont change the IP.

For get IP, see:

  1. Open CMD
  2. Type "ipconfig" (without quotation marks)
  3. Press "Enter"
  4. Your ip, subnet, mask and default gateway will be returned to you
  5. Copy IP by the line IPv4 Address: xxx.xxx.xxx.xxx
  6. Assuming you have returned something like "192.168.1.113" you must access the address to your "android device" like this: 192.168.1.113:3306

Read about "local ip/Private addresses": http://en.wikipedia.org/wiki/IP_address#IPv4_private_addresses

Note: 10.0.0.1, 10.1.1.1, 192.168.0.1, 192.168.1.1 are IPs privates from ROUTER and non-PC, ie they will never be assigned to other computers because they belong to the router

Emulator:

Running both MysqlServer and Emulator in you computer 127.0.0.1:(port)

The 10.0.2.2 (ie 10.0.2.2:3306) is the solution to that problem.

The emulator runs on a "virtual network", ie is not in the same network as your router.

Emulator Networking details:

  1. 10.0.2.1 Router/gateway address
  2. 10.0.2.2 Special alias to your host loopback interface (i.e., 127.0.0.1 on your development machine)
  3. 10.0.2.3 First DNS server
  4. 127.0.0.1 The emulated device's own loopback interface

Read: http://developer.android.com/tools/devices/emulator.html

127.0.0.1

127.0.0.1 accesses only the localhost, ie when trying to access localhost with the emulator you try to open own emulator instead of the PC.

http://en.wikipedia.org/wiki/Localhost

Post a Comment for "Can't Connect To Mysql From Android Device"