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

MySQL连接报错:CommunicationsException及No Route to Host问题求助

Hey there, let’s troubleshoot this MySQL connection problem together—those communications link errors can be tricky, but we’ll go through the most common fixes step by step:

1. Make Sure the MySQL Service is Running
  • Hit Win + R, type services.msc and press Enter. Look for your MySQL service (it might be named something like MySQL57 depending on your installation). Check if its status says Running. If not, right-click it and select "Start". You can also set it to "Automatic" so it launches on boot.
2. Verify the MySQL Port is 3306 and Not Occupied
  • Locate your MySQL config file (usually in C:\ProgramData\MySQL\MySQL Server 5.7\my.ini—note that ProgramData is a hidden folder). Find the line port=3306 to confirm the port matches what’s in your code.
  • Open Command Prompt and run:
    netstat -ano | findstr "3306"
    
    This will show if another process is using port 3306. If it is, either change MySQL’s port in the config file or close the conflicting program.
3. Check MySQL User Permissions and Credentials
  • Open the MySQL command line client, log in as root, and run this query:
    SELECT user, host FROM mysql.user WHERE user='root';
    
    Ensure the host value for root is localhost, 127.0.0.1, or % (which allows remote connections). If it’s not, update the permissions with:
    GRANT ALL PRIVILEGES ON test.* TO 'root'@'localhost' IDENTIFIED BY 'shruthi@123';
    FLUSH PRIVILEGES;
    
  • Double-check that your password shruthi@123 is correct—sometimes special characters can cause unexpected issues. Try testing with a simple password first to rule this out.
4. Check Windows Firewall Settings
  • Windows Firewall might be blocking your Java/Eclipse program from accessing port 3306. Temporarily disable the firewall to test if the connection works. If it does, add an exception:
    1. Open "Windows Defender Firewall" → "Advanced Settings"
    2. Go to "Outbound Rules" → "New Rule"
    3. Select "Program", browse to your Eclipse eclipse.exe or Java java.exe file, and allow it to connect through the firewall.
5. Ensure Your JDBC Driver is Compatible
  • You’re using com.mysql.jdbc.Driver, which is correct for MySQL 5.x, but make sure your driver version matches MySQL 5.7.2. Download a compatible version (like mysql-connector-java-5.1.49), add it to your Eclipse project’s lib folder, and add it to the build path.
  • Alternatively, you can try the newer driver class com.mysql.cj.jdbc.Driver (though it’s more common for MySQL 8+, but it might work here) and update your URL to include timezone settings:
    String url = "jdbc:mysql://localhost:3306/test?useSSL=false&serverTimezone=UTC";
    
6. Test Local Connection Outside of Eclipse
  • First, confirm you can connect to the test database using MySQL Workbench or the command line client. If even that fails, the issue is with your MySQL installation, not your code. If it works, then the problem is isolated to your Eclipse setup or code.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.21 07:27:57