You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android连接本地MySQL数据库(VertrigoServ)授权无效崩溃问题求助

Fixing "Invalid authorization" Crash When Connecting Android App to MySQL via VertrigoServ

Hey there, let's tackle that frustrating "Invalid authorization" error and app crash you're dealing with. I've seen this exact issue a bunch of times when connecting Android apps to local MySQL setups, so let's break down the most likely fixes step by step:

1. Double-Check MySQL User Permissions & Credentials

  • First off, make sure the username and password you're using in your Android code exactly match what's configured in your VertrigoServ MySQL instance. Vertrigo sometimes uses a default root user with an empty password, but if you set a custom password, don't forget it!
  • A super common gotcha: MySQL's default root user is often restricted to only localhost (your laptop itself) access. Since your Android device is connecting over the network, you need to grant external access to your user. Run these commands in MySQL (you can use Vertrigo's phpMyAdmin or a MySQL client):
    GRANT ALL PRIVILEGES ON *.* TO 'your_username'@'%' IDENTIFIED BY 'your_password' WITH GRANT OPTION;
    FLUSH PRIVILEGES;
    
    The % allows access from any IP—for better security, you can replace it with your Android device's specific local IP address once you get it working.

2. Verify VertrigoServ MySQL Configuration

  • Open your VertrigoServ MySQL config file (usually my.ini in the mysql folder of your Vertrigo installation). Look for the bind-address line:
    • If it's set to 127.0.0.1, only your laptop can connect. Change it to 0.0.0.0 to allow connections from all devices on the network.
  • Make sure the MySQL service in VertrigoServ is running—restart it after making config changes to apply them.

3. Fix Your Android Connection Parameters

  • Don't use 127.0.0.1 as the database IP—that points to your Android device itself, not your laptop. Instead, use your laptop's local network IP (like 192.168.1.102). Find this by running ipconfig (Windows) or ifconfig (Mac/Linux) on your laptop.
  • Confirm the port number matches Vertrigo's MySQL port (default is 3306—if you changed it, update your code accordingly).
  • Double-check that the database name in your code is identical to what you created in MySQL (case-sensitive depending on your setup!).

4. Rule Out Network & Firewall Issues

  • Ensure your Android device and laptop are on the same Wi-Fi network. Test connectivity by pinging your laptop's IP from your device (you can use a ping app or terminal if you have developer tools set up).
  • Open your laptop's firewall to allow incoming connections on port 3306. For Windows, go to Firewall > Advanced Settings > Inbound Rules, then add a new rule allowing TCP traffic on port 3306 for your local network.

5. Code-Specific Fixes

  • Never run database/network operations on the main thread—Android will throw a NetworkOnMainThreadException which can cause crashes (even if your logs say "Invalid authorization"). Move your database code to an AsyncTask, Kotlin Coroutine, or background thread.
  • Make sure you've added the internet permission to your AndroidManifest.xml:
    <uses-permission android:name="android.permission.INTERNET" />
    
  • Try adjusting your JDBC connection string to include these flags, which often resolve authorization/SSL hiccups in local setups:
    String dbUrl = "jdbc:mysql://192.168.1.102:3306/your_db_name?useSSL=false&allowPublicKeyRetrieval=true";
    

Start with checking credentials and user permissions—those are the most common culprits here. Let me know if you hit any snags along the way!

内容的提问来源于stack exchange,提问作者Filippo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 07:53:11