apache/druid · error · IllegalArgumentException
Invalid URL format for MySQL: [%s]
Error message
Invalid URL format for MySQL: [%s]
What it means
Thrown by ConnectionUriUtils.tryParseMySqlConnectionUri when the MySQL Connector/J ConnectionUrl class reports acceptsUrl(uri)==false for the given JDBC URI. Druid parses JDBC URIs reflectively to extract host/port/db properties (e.g. for extension metadata), and this check guards against URIs the MySQL driver cannot accept at all.
Source
Thrown at processing/src/main/java/org/apache/druid/utils/ConnectionUriUtils.java:207
Class<?> driverClass = Class.forName(POSTGRES_DRIVER);
Method parseUrl = driverClass.getMethod("parseURL", String.class, Properties.class);
Properties properties = (Properties) parseUrl.invoke(null, connectionUri, null);
if (properties == null) {
throw new IAE("Invalid URL format for PostgreSQL: [%s]", connectionUri);
}
Set<String> keys = Sets.newHashSetWithExpectedSize(properties.size());
properties.forEach((k, v) -> keys.add((String) k));
return keys;
}
public static Set<String> tryParseMySqlConnectionUri(String connectionUri)
throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException,
InvocationTargetException
{
Class<?> connectionUrlClass = Class.forName(MYSQL_CONNECTION_URL);
Method isConnectionStringSupported = connectionUrlClass.getMethod("acceptsUrl", String.class);
if (!(boolean) isConnectionStringSupported.invoke(connectionUrlClass, connectionUri)) {
throw new IAE("Invalid URL format for MySQL: [%s]", connectionUri);
}
Method getConnectionUrlInstanceMethod = connectionUrlClass.getMethod("getConnectionUrlInstance", String.class, Properties.class);
Object conUrl = getConnectionUrlInstanceMethod.invoke(connectionUrlClass, connectionUri, null);
Method getHostsList = connectionUrlClass.getMethod("getHostsList");
return getKeysFromOptions(getPropertiesFromHosts((List<?>) getHostsList.invoke(conUrl)));
}
private static Properties getPropertiesFromHosts(List<?> hostsList)
throws NoSuchMethodException, InvocationTargetException, IllegalAccessException, ClassNotFoundException
{
Properties properties = new Properties();
Class<?> hostInfoClass = Class.forName(MYSQL_HOST_INFO);
for (Object host : hostsList) {
Method getHostMethod = hostInfoClass.getMethod("getHost");
String hostName = (String) getHostMethod.invoke(host);
if (hostName != null) {
properties.setProperty("HOST", hostName);
}View on GitHub (pinned to 9b90983fd2)
Solutions
- Verify the URI starts with jdbc:mysql:// and follows the documented Connector/J URL syntax
- Confirm the intended MySQL Connector/J jar is on the classpath and matches the URL dialect
- Log the full connectionUri and test it with a plain DriverManager.getConnection to see the driver's own complaint
- If the URI belongs to another database, ensure it is routed to the correct parser, not the MySQL one
Example fix
// before String uri = "jdbc:mysql//localhost:3306/druid"; // after String uri = "jdbc:mysql://localhost:3306/druid";
Defensive patterns
Strategy: try-catch
Validate before calling
boolean valid = uri != null && uri.startsWith("jdbc:mysql://");
if (valid) {
try { java.sql.DriverManager.getConnection(uri + (uri.contains("?") ? "&" : "?") + "connectTimeout=1000"); }
catch (Exception e) { /* driver rejects it */ }
} Type guard
static boolean looksLikeMySqlJdbcUri(String uri) {
return uri != null && uri.regionMatches(true, 0, "jdbc:mysql://", 0, 13);
} Try / catch
try {
params = ConnectionUriUtils.tryParseJdbcUriParameters(uri);
} catch (IllegalArgumentException e) {
if (e.getMessage() != null && e.getMessage().contains("Invalid URL format for MySQL")) {
log.error("Rejecting malformed MySQL URI: {}", uri, e);
}
throw e;
} Prevention
- Always build mysql URIs as jdbc:mysql://host:port/db?params
- Test generated connection strings against DriverManager before persisting them
- Keep the MySQL Connector/J version aligned with the URL dialect in use
When it happens
Trigger: Calling tryParseJdbcUriParameters (directly or via its callers) with a jdbc:mysql: URL that MySQL Connector/J rejects: wrong scheme spelling, missing '//' after jdbc:mysql:, unsupported MySQL X DevAPI forms, or a URI scheme routed to the MySQL parser that is not actually a mysql URL.
Common situations: Typos like 'jdbc:mysql//host:3306/db', copy-pasted URIs from other databases, dynamically built connection strings with empty or malformed host sections, or a mismatched mysql-connector-java version on the classpath that no longer accepts the URL shape.
Understand the failure class
Background: "Invalid URL" errors: why new URL(), URI.parse, and reqwest::Url reject your string — missing scheme, whitespace, and bad path format — this error's family across 39 libraries.
Related errors
- Failed to find MySQL driver class. Please check the MySQL co
- Invalid URL format for MariaDB: [%s]
- JDBC Kerberos auth not supported yet
- JDBC driver JAR files missing from extensions/druid-lookups-
- JDBC driver JAR files missing in the classpath
AI-assisted analysis of apache/druid@9b90983fd2 (2026-09-07).
Data as JSON: /api/errors/a31eacc6011bc78f.
Report an issue: GitHub.