android与mysql连接不上去,无法连接从Android设备到mysql
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 succesfully sent to the serv
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 succesfully sent to the server was 0 milliseconds ago.
the driver has not recieved any packets from the server"
my firewall port 3306 is opened.
i have also granted permissions in mysql:
CREATE USER 'root'@'%' IDENTIFIED BY '1234';
FLUSH PRIVILEGES;
access to mysql in my PC (localhost), works fine.
my PC is running on windows 7 and i am using the latest mysql workbench (version 6.0).
i am trying to connect through my wi-fi router.
i tried giving theses IPs for my PC on my android device:
127.0.0.1
10.0.0.1
can you please advise me what else should i do in order to be able to access the mysql database on my PC from my tablet?
解决方案
Solution Intranet/Lan (probably wi-fi):
If your Android Device is on LAN NetWork (probably wi-fi), you have to use the "lan ip".
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)
In your App (on android device) access something like 192.168.1.101:3306
Tip: recommend setting (manually) the IP of your computer because the router wont change the IP.
For get IP, see:
Open CMD
Type "ipconfig" (without quotation marks)
Press "Enter"
Your ip, subnet, mask and default gateway will be returned to you
Copy IP by the line IPv4 Address: xxx.xxx.xxx.xxx
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
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:
10.0.2.1 Router/gateway address
10.0.2.2 Special alias to your host loopback interface (i.e., 127.0.0.1 on your development machine)
10.0.2.3 First DNS server
127.0.0.1 The emulated device's own loopback interface
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.
更多推荐
所有评论(0)