{"record":{"id":"3e1eed7d2ade1b9d","repo":"MyCATApache/Mycat-Server","slug":"can-t-find-table-define-in-schema-tablename-s","errorCode":null,"errorMessage":"can't find table define in schema + tableName +  schema: + schema.getName()","messagePattern":"can't find table define in schema \\+ tableName \\+  schema: \\+ schema\\.getName\\(\\)","errorType":"exception","errorClass":"SQLNonTransientException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/route/util/RouterUtil.java","lineNumber":1374,"sourceCode":"\t}\r\n\r\n\r\n\t/**\r\n\t *\r\n\t * 单表路由\r\n\t */\r\n\tpublic static RouteResultset tryRouteForOneTable(SchemaConfig schema, DruidShardingParseInfo ctx,\r\n\t\t\tRouteCalculateUnit routeUnit, String tableName, RouteResultset rrs, boolean isSelect,\r\n\t\t\tLayerCachePool cachePool) throws SQLNonTransientException {\r\n\r\n\t\tif (isNoSharding(schema, tableName)) {\r\n\t\t\treturn routeToSingleNode(rrs, schema.getDataNode(), ctx.getSql());\r\n\t\t}\r\n\r\n\t\tTableConfig tc = schema.getTables().get(tableName);\r\n\t\tif(tc == null) {\r\n\t\t\tString msg = \"can't find table define in schema \" + tableName + \" schema:\" + schema.getName();\r\n\t\t\tLOGGER.warn(msg);\r\n\t\t\tthrow new SQLNonTransientException(msg);\r\n\t\t}\r\n\r\n\t\tMap<String, Map<String, Set<ColumnRoutePair>>> tablesAndConditions = routeUnit.getTablesAndConditions();\r\n        if(tc.isDistTable()){\r\n            Set<String> keySet = tablesAndConditions.keySet();\r\n            //Map.Entry<String, Map<String, Set<ColumnRoutePair>>> entry = (Entry<String, Map<String, Set<ColumnRoutePair>>>) tablesAndConditions.get(keySet.toArray()[0]);\r\n            return routeToDistTableNode(schema,rrs,ctx.getSql(), tablesAndConditions, cachePool,isSelect, null);\r\n        }\r\n\r\n\t\tif(tc.isGlobalTable()) {//全局表\r\n\t\t\tif(isSelect) {\r\n\t\t\t\t// global select ,not cache route result\r\n\t\t\t\trrs.setCacheAble(false);\r\n\t\t\t\treturn routeToSingleNode(rrs, getAliveRandomDataNode(tc)/*getRandomDataNode(tc)*/, ctx.getSql());\r\n\t\t\t} else {//insert into 全局表的记录\r\n\t\t\t\treturn routeToMultiNode(false, rrs, tc.getDataNodes(), ctx.getSql(),true);\r\n\t\t\t}\r","sourceCodeStart":1356,"sourceCodeEnd":1392,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/route/util/RouterUtil.java#L1356-L1392","documentation":"RouterUtil's route-by-table-name path looks up TableConfig for the target table in the schema's table map. A null TableConfig means the table is not declared in MyCat's schema.xml, and since the schema has no single default dataNode to fall back to, it throws SQLNonTransientException.","triggerScenarios":"Executing a statement routed through this method (e.g. a routeUnit for one table) where schema.getTables().get(tableName) returns null — table absent from schema.xml for that logical schema.","commonSituations":"Querying a table that only exists in the backend MySQL, not declared to MyCat; case-sensitivity mismatch (MyCat compares uppercase table names); using a schema alias that lacks the table definition; config file edits not reloaded.","solutions":["Declare the table in schema.xml under the correct schema and reload the configuration","Give the schema a default dataNode so unknown tables route to a single node","Uppercase/normalize the table name in your SQL to match the declared name","Confirm which MyCat schema your connection targets (SHOW DATABASES via MyCat)"],"exampleFix":"// before\nSELECT * FROM customer;\n// after (schema.xml gains)\n<table name=\"customer\" dataNode=\"dn1\" rule=\"rule1\"/>","handlingStrategy":"validation","validationCode":"// check MyCat sees the table before routing\nResultSet rs = stmt.executeQuery(\"SHOW TABLES LIKE '\" + tableName.toUpperCase() + \"'\");\nif (!rs.next()) throw new IllegalStateException(\"Table \" + tableName + \" not configured in MyCat schema.xml\");","typeGuard":null,"tryCatchPattern":"try {\n    execute(sql);\n} catch (SQLNonTransientException e) {\n    if (e.getMessage().startsWith(\"can't find table define in schema\")) {\n        // fail fast with config guidance\n        throw new IllegalStateException(\"Add <table name='...'> to schema.xml and run reload @@config\", e);\n    }\n    throw e;\n}","preventionTips":["Generate MyCat table declarations from the source DB schema in CI","Reload config after every schema.xml change","Use uppercase table names in SQL to match MyCat's normalized lookup"],"tags":["sql","routing","schema-config","mycat"],"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"}