How to connect Android emulator with local mysql database

空扰寡人 提交于 2019-12-04 16:38:26

If you're running this within the emulator localhost:3306 won't work. Replace that with the IP address of the machine running MySQL. So for example if your local dev machine (running MySQL) uses IP 192.168.0.10, change that to 192.168.0.10:3306.

Just to expand a bit - when you attempt to access http://localhost:3306 within the emulator (or even on a device) it tries to connect to the port 3306 on the loopback address (on the emulator/device). You obviously don't have the SQL service running on the android so this doesn't make sense.

Also, depending on your OS configuration, you may have to open port 3306 in your firewall.

Edit: Warren's tip (below) leads me to the details in the Android docs. May want to stick with 10.0.2.2 if you don't want to mess around with your OS' firewall.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!