如何使用IntelliJ Database Navigator插件连接MySQL服务器?连接失败求助
Hey there! Let's figure out why you can't connect your self-hosted MySQL server to IntelliJ's Database Navigator—even when your username and password are correct. Since I can't view the screenshot directly, I’ll cover the most common culprits and fixes that usually resolve this kind of connection issue.
1. Check if MySQL allows remote connections
By default, MySQL is set to only accept connections from localhost (the same machine it’s running on). If your app and MySQL are on different machines (or even if you’re testing locally but using a non-loopback IP), this will block you:
- Open your MySQL config file (it’s usually
my.cnfon Linux/macOS,my.inion Windows) - Look for the
bind-addressline and change it to0.0.0.0(to allow all IPs) or your specific client IP address - Restart the MySQL service:
- Linux:
sudo systemctl restart mysql - Windows: Open the Services app, find MySQL, and click Restart
- Linux:
- Next, grant your user permission to connect from your client machine. Run this in the MySQL shell:
ReplaceGRANT ALL PRIVILEGES ON *.* TO 'your_username'@'%' IDENTIFIED BY 'your_password'; FLUSH PRIVILEGES;your_usernameandyour_passwordwith your actual credentials. The%lets the user connect from any IP—for better security, replace it with your client’s exact IP later.
2. Verify your firewall isn’t blocking port 3306
MySQL uses port 3306 by default, and firewalls often block this port by default:
- Linux: Check if the port is open with
sudo ufw status. If not, allow it withsudo ufw allow 3306/tcp - Windows: Open Windows Defender Firewall > Advanced Settings > Inbound Rules, then create a new rule to allow TCP traffic on port 3306
- macOS: Go to System Settings > Network > Firewall > Options, and add MySQL to the list of allowed apps
3. Double-check IntelliJ’s connection settings
Even small mistakes here can cause failures:
- Host: Make sure you’re using the correct IP of your MySQL server (don’t use
localhostif it’s a remote server) - Port: Confirm it’s set to 3306 (or your custom port if you changed it during setup)
- Authentication Method: Try switching between
StandardandMySQL Native Password—newer MySQL versions usecaching_sha2_passwordwhich can have compatibility issues with older JDBC drivers - Database: If you’re targeting a specific database, ensure it exists in MySQL; you can leave this blank to connect to the server first and browse databases later
4. Update the JDBC driver in IntelliJ
Outdated drivers are a common source of connection problems. When setting up your connection in IntelliJ, look for a prompt that says "Download" next to the driver version. Click it to install the latest MySQL JDBC driver—this often fixes compatibility gaps.
Quick Test to Narrow Things Down
First, try connecting to MySQL using the command line to rule out server-side issues:
mysql -h your_server_ip -u your_username -p
If this works, the problem is definitely with IntelliJ’s settings. If it fails, focus on fixing MySQL’s remote access or firewall rules first.
内容的提问来源于stack exchange,提问作者Salim

