求助:Artifactory无法连接至MySQL主机故障排查
It looks like your Artifactory container is stuck at "Preparing to run Artifactory..." because it can’t establish a connection to your MySQL host. Let’s walk through the most common fixes based on your command and setup:
1. Fix the Typo in Your DB_PASSWORD Variable
First, I spotted a small but critical typo: your DB_PASSWORD value is my_passowrd (extra 'o'). Correct this to my_password and restart the container—even tiny typos like this will block authentication.
2. Validate Your JDBC URL Format
Your DB_URL uses & instead of the standard & for separating URL parameters. JDBC strings require & directly, not the HTML entity escape. Update your URL to:
jdbc:mysql://my_host_ip:3306/some_db?characterEncoding=UTF-8&elideSetAutoCommits=true
This ensures the database driver parses the parameters correctly.
3. Check MySQL Host Accessibility
Since you’re using --net=host, the container shares your host’s network stack, but we still need to confirm MySQL is reachable:
- From your host machine, run
mysql -h my_host_ip -u my_db_user -pand enter your password. If this fails, your MySQL server isn’t accepting connections from that IP. - Open your MySQL config file (usually
my.cnformy.ini) and check thebind-addresssetting. It should be set to0.0.0.0to allow connections from external IPs (not just127.0.0.1). Restart MySQL after making changes. - Ensure your firewall (on the MySQL host) allows incoming traffic on port 3306.
4. Confirm Connector Compatibility
You’re using mysql-connector-java-5.1.46.jar—this version is incompatible with MySQL 8.0+ because it doesn’t support the new caching_sha2_password authentication plugin:
- If your MySQL server is 8.x, replace the connector with a newer version (e.g., 8.0.33) and update the mount path accordingly.
- Verify the connector is properly mounted in the container:
Make sure the connector jar appears in the list.docker exec -it artifactory-host-mysql ls /opt/jfrog/artifactory/tomcat/lib/
5. Check Database Existence and User Permissions
- Ensure the
some_dbdatabase exists on your MySQL server. Run this in the MySQL shell:
If it doesn’t exist, create it withSHOW DATABASES;CREATE DATABASE some_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;. - Grant full permissions to your user for the database:
TheGRANT ALL PRIVILEGES ON some_db.* TO 'my_db_user'@'%' IDENTIFIED BY 'my_password'; FLUSH PRIVILEGES;%allows connections from any IP—you can restrict it to your host IP if needed.
6. Inspect Container Logs for Detailed Errors
The "Preparing to run Artifactory..." message doesn’t show the root cause. Get the full logs with:
docker logs artifactory-host-mysql
Look for lines containing "ERROR" or "Connection refused"—these will tell you exactly what’s failing (e.g., authentication denied, unknown database, or network issues).
Once you’ve addressed these steps, stop and restart the container with the corrected command. If you still run into issues, share the relevant log lines and we can dig deeper.
内容的提问来源于stack exchange,提问作者Prakashsinha Bayas

