{"record":{"id":"eb6c70aed8ab7eb6","repo":"MyCATApache/Mycat-Server","slug":"can-t-find-table-define-of-table-in-schem","errorCode":null,"errorMessage":"\"can't find table define of \" + table + \" in schema:\" + schema.getName()","messagePattern":"\"can't find table define of \" \\+ table \\+ \" in schema:\" \\+ schema\\.getName\\(\\)","errorType":"exception","errorClass":"SQLNonTransientException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/route/parser/druid/impl/DruidLockTableParser.java","lineNumber":33,"sourceCode":"import io.mycat.route.parser.druid.MycatSchemaStatVisitor;\nimport io.mycat.server.parser.ServerParse;\nimport io.mycat.util.SplitUtil;\n\n/**\n * lock tables [table] [write|read]语句解析器\n * @author songdabin\n */\npublic class DruidLockTableParser extends DefaultDruidParser implements DruidParser {\n\t@Override\n\tpublic void statementParse(SchemaConfig schema, RouteResultset rrs, SQLStatement stmt)\n\t\t\tthrows SQLNonTransientException {\n\t\tMySqlLockTableStatement lockTableStat = (MySqlLockTableStatement)stmt;\n\t\tString table = lockTableStat.getItems().get(0).getTableSource().toString().toUpperCase();\n\t\tTableConfig tableConfig = schema.getTables().get(table);\n\t\tif (tableConfig == null) {\n\t\t\tString msg = \"can't find table define of \" + table + \" in schema:\" + schema.getName();\n\t\t\tLOGGER.warn(msg);\n\t\t\tthrow new SQLNonTransientException(msg);\n\t\t}\n\t\tLockType lockType = lockTableStat.getItems().get(0).getLockType();\n\t\tif (LockType.WRITE != lockType && LockType.READ != lockType) {\n\t\t\tString msg = \"lock type must be write or read\";\n\t\t\tLOGGER.warn(msg);\n\t\t\tthrow new SQLNonTransientException(msg);\n\t\t}\n\t\tList<String> dataNodes = tableConfig.getDataNodes();\n\t\tRouteResultsetNode[] nodes = new RouteResultsetNode[dataNodes.size()];\n\t\tfor (int i = 0; i < dataNodes.size(); i ++) {\n\t\t\tnodes[i] = new RouteResultsetNode(dataNodes.get(i), ServerParse.LOCK, stmt.toString());\n\t\t}\n\t\trrs.setNodes(nodes);\n\t\trrs.setFinishedRoute(true);\n\t}\n\t\n\t@Override\n\tpublic void visitorParse(SchemaConfig schema, RouteResultset rrs, SQLStatement stmt, MycatSchemaStatVisitor visitor)","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/route/parser/druid/impl/DruidLockTableParser.java#L15-L51","documentation":"Mycat's LOCK TABLES statement parser requires the locked table to be defined in the current logical schema's table configuration. When the parsed table name (uppercased) is not found in schema.getTables(), routing is impossible, so a SQLNonTransientException is thrown after logging a warning.","triggerScenarios":"Executing `LOCK TABLES <name> WRITE|READ` where <name> is not declared in the schema's <table> entries in schema.xml, or the statement's table name differs in case/format from the configured table name.","commonSituations":"Locking a table that exists only on the backend MySQL but was never added to Mycat's schema.xml; typos or case mismatches between the SQL table name and the configured logical table; running LOCK TABLES against Mycat-managed schemas without configuring the table as a sharding/global table.","solutions":["Add the table to schema.xml as a <table> entry in the schema being used, then reload the Mycat config","Verify the table name in the LOCK TABLES statement exactly matches the configured table name (parser compares uppercased names)","Route LOCK TABLES statements to a backend MySQL directly instead of through Mycat, as support is limited to WRITE/READ lock types on configured tables"],"exampleFix":"<!-- before: schema.xml missing table -->\n<schema name=\"db1\">\n  <table name=\"t_user\" dataNode=\"dn1\"/>\n</schema>\n<!-- after: table locked by the app is declared -->\n<schema name=\"db1\">\n  <table name=\"t_user\" dataNode=\"dn1\"/>\n  <table name=\"t_lock\" dataNode=\"dn1\"/>\n</schema>","handlingStrategy":"validation","validationCode":"TableConfig tc = schema.getTables().get(tableName.toUpperCase());\nif (tc == null) throw new IllegalStateException(\"table not in mycat schema.xml: \" + tableName);","typeGuard":"if (schema != null && schema.getTables() != null && schema.getTables().containsKey(table.toUpperCase())) { ... }","tryCatchPattern":"try { route(...); } catch (SQLNonTransientException e) { if (e.getMessage().startsWith(\"can't find table define\")) { fixSchemaConfig(); } else throw e; }","preventionTips":["Declare every table your app locks in schema.xml","Keep table names consistent in case between SQL and config","Reload Mycat config after schema.xml edits","Prefer direct backend connections for admin/maintenance SQL like LOCK TABLES"],"tags":["mysql","routing","schema-config","lock-tables"],"backgroundTag":"resource-not-found","analyzedSha":"65f8d8beb752f935752f2a0eec0ab017facab9ef","analyzedAt":"2026-09-11T00:12:21.696Z","contentChangedAt":"2026-09-11T00:12:21.696Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}