MyCATApache/Mycat-Server · error
ER_PARSE_ERROR
ER_PARSE_ERROR
Error message
msg == null ? e.getClass().getSimpleName() : msg
What it means
DruidMycatRouteStrategy.doExecute routes a multi-statement SQL through the Druid parser/router. If routing throws (parse error, unknown table, config problem), the exception is logged and its message — or the exception class simple name when the message is null — is sent to the client as an ER_PARSE_ERROR MySQL error. This is the generic 'your statement could not be routed' failure of the Druid-based strategy.
Solutions
- Look at the server log line ending with 'err:' to see the full stack trace of the real routing exception.
- Fix the SQL syntax to something Druid supports, or upgrade the Druid dependency for newer MySQL syntax support.
- Ensure the referenced tables/schemas/dataNodes exist in schema.xml with correct primaryKey settings.
- If the client message is just a class name (message was null), reproduce in tests to capture the actual NPE cause and fix the config/route logic.
Example fix
// before: SQL Druid cannot parse (MySQL 8 CTE variant) WITH cte AS (SELECT ...) SELECT * FROM cte; // after: rewrite with a subquery or upgrade Druid SELECT * FROM (SELECT ...) AS cte;
Defensive patterns
Strategy: try-catch
Validate before calling
// check the statement targets configured tables before routing
for (String tbl : extractTables(sql)) {
if (!mycatSchema.tablesContain(tbl)) throw new IllegalStateException("table not configured: " + tbl);
} Try / catch
try {
stmt.execute(sql);
} catch (SQLException e) {
if (e.getErrorCode() == 1064 /* ER_PARSE_ERROR */) {
logger.error("route/parse failed, check server log 'err:' line; sql={}", sql);
}
} Prevention
- Test new SQL syntax against the bundled Druid version before release.
- Keep schema.xml table definitions in sync with the database.
- Upgrade Druid when adopting newer MySQL syntax.
- Read the full server-side stack trace — the client message may be just the exception class name.
When it happens
Trigger: Executing SQL that Druid's parser cannot handle (unsupported syntax, MySQL 8 features, comments/hints Druid rejects), or routing throwing due to missing schema/table/primaryKey configuration; also e.getMessage() returning null (e.g. NPE) which degrades to the exception class name in the client error.
Common situations: Statements with newer MySQL syntax unsupported by the bundled Druid version, queries against tables absent from schema.xml, NPEs during routing producing 'NullPointerException' as the client-visible message, multi-statement strings where one clause fails.
Understand the failure class
Background: "query failed", "%w: SQL error" — wrapped database query errors in Go libraries explained — this error's family across 3 libraries.
Related errors
- 无效的SQL语句
- schema: ,table: ,sql: is not allowed,because table is…
- load crc32slot datafile error:dn=
- can't find hint datanode
- can't find hint schema
AI-assisted analysis of MyCATApache/Mycat-Server@65f8d8beb7 (2026-09-11).
Data as JSON: /api/errors/36987ef4efa2a59f.
Report an issue: GitHub.
Appendix: source
Thrown at src/main/java/io/mycat/route/impl/DruidMycatRouteStrategy.java:363
public void doExecute(List param) {
sc.getSession2().setMiddlerResultHandler(null);
String sqls = null;
// 路由计算
RouteResultset rrs = null;
try {
sqls = buildSql(statement,sqlselect,param);
rrs = MycatServer
.getInstance()
.getRouterservice()
.route(MycatServer.getInstance().getConfig().getSystem(),
schema, sqlType,sqls.toLowerCase(), charset,sc );
} catch (Exception e) {
StringBuilder s = new StringBuilder();
LOGGER.warn(s.append(this).append(sqls).toString() + " err:" + e.toString(),e);
String msg = e.getMessage();
sc.writeErrMessage(ErrorCode.ER_PARSE_ERROR, msg == null ? e.getClass().getSimpleName() : msg);
return;
}
NonBlockingSession noBlockSession = new NonBlockingSession(sc.getSession2().getSource());
noBlockSession.setMiddlerResultHandler(null);
//session的预编译标示传递
noBlockSession.setPrepared(sc.getSession2().isPrepared());
if (rrs != null) {
noBlockSession.setCanClose(false);
noBlockSession.execute(rrs, ServerParse.SELECT);
}
}
} );
sc.getSession2().setMiddlerResultHandler(middlerResultHandler);
sc.getSession2().setCanClose(false);
// 路由计算
RouteResultset rrs = null;
try {View on GitHub (pinned to 65f8d8beb7)