{"record":{"id":"0d81588a41b9f2bf","repo":"MyCATApache/Mycat-Server","slug":"can-t-find-table-define-in-schema-tablename-al","errorCode":null,"errorMessage":"can't find table define in schema + tableName + alias：+ alias + , schema: + schema.getName()","messagePattern":"can't find table define in schema \\+ tableName \\+ alias：\\+ alias \\+ , schema: \\+ schema\\.getName\\(\\)","errorType":"exception","errorClass":"SQLNonTransientException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/route/util/RouterUtil.java","lineNumber":1263,"sourceCode":"\t\t//为全局表和单库表找路由\r\n\t\tfor(String tableName : tables) {\r\n\r\n\t\t\tTableConfig tableConfig = schema.getTables().get(tableName.toUpperCase());\r\n\r\n\t\t\tif(tableConfig == null) {\r\n\t\t\t\t//add 如果表读取不到则先将表名从别名中读取转化后再读取\r\n\t\t\t\tString alias = ctx.getTableAliasMap().get(tableName);\r\n\t\t\t\tif(!StringUtil.isEmpty(alias)){\r\n\t\t\t\t\ttableConfig = schema.getTables().get(alias.toUpperCase());\r\n\t\t\t\t}\r\n\r\n\t\t\t\tif(tableConfig == null){\r\n\t\t\t\t\tif (StringUtils.isNotEmpty(schema.getDataNode())) {\r\n\t\t\t\t\t\treturn routeToSingleNode(rrs, schema.getDataNode(), ctx.getSql());\r\n\t\t\t\t\t} else {\r\n\t\t\t\t\t\tString msg = \"can't find table define in schema \" + tableName + \" alias：\" + alias + \", schema:\"\r\n\t\t\t\t\t\t\t\t+ schema.getName();\r\n\t\t\t\t\t\tLOGGER.warn(msg);\r\n\t\t\t\t\t\tthrow new SQLNonTransientException(msg);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t}\r\n\t\t\tif(tableConfig.isGlobalTable()) {//全局表\r\n\t\t\t\tif(tablesRouteMap.get(tableName) == null) {\r\n\t\t\t\t\ttablesRouteMap.put(tableName, new HashSet<String>());\r\n\t\t\t\t}\r\n\t\t\t\ttablesRouteMap.get(tableName).addAll(tableConfig.getDataNodes());\r\n\t\t\t} else if(tablesRouteMap.get(tableName) == null) { //余下的表都是单库表\r\n\t\t\t\ttablesRouteMap.put(tableName, new HashSet<String>());\r\n\t\t\t\ttablesRouteMap.get(tableName).addAll(tableConfig.getDataNodes());\r\n\t\t\t}\r\n\r\n\t\t\tif(tableConfig.getDistTables().size() > 0) {\r\n\t\t\t\tMap<String, List<String>> subTablesmap = rrs.getSubTableMaps();\r\n\t\t\t\tif (subTablesmap == null) {\r","sourceCodeStart":1245,"sourceCodeEnd":1281,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/route/util/RouterUtil.java#L1245-L1281","documentation":"During query routing with a table alias, RouterUtil resolves the (alias-stripped) table name against the current schema's TableConfig map. If the table is not defined in the MyCat schema config and the schema has no default dataNode, routing cannot proceed and it throws SQLNonTransientException.","triggerScenarios":"Running a SELECT (or other routed statement) that references table 'tableName' with alias 'alias', where schema.xml has no <table name=\"tableName\"> under the schema and the schema lacks a dataNode attribute.","commonSituations":"Table exists in MySQL but was never declared in MyCat's schema.xml; typo in table name or case mismatch; connecting to the wrong MyCat logical schema; recently added table not reloaded into config.","solutions":["Add the missing table to schema.xml: <table name=\"tableName\" dataNode=\"dn1\" .../> and reload MyCat config","Add a default dataNode to the schema so undeclared tables can be routed: <schema name=\"...\" dataNode=\"dn1\">","Verify table name spelling and case (MyCat uppercases table names when looking up)","Check you are connected to the intended logical schema in MyCat"],"exampleFix":"// before (schema.xml)\n<schema name=\"testdb\">\n  <table name=\"orders\" dataNode=\"dn1\"/>\n</schema>\n// after\n<schema name=\"testdb\">\n  <table name=\"orders\" dataNode=\"dn1\"/>\n  <table name=\"customers\" dataNode=\"dn1\"/>\n</schema>","handlingStrategy":"validation","validationCode":"// before executing, verify the table is declared in MyCat\ntry (ResultSet rs = stmt.executeQuery(\"SHOW TABLES\")) {\n    Set<String> known = new HashSet<>();\n    while (rs.next()) known.add(rs.getString(1).toUpperCase());\n    if (!known.contains(tableName.toUpperCase()))\n        throw new IllegalStateException(tableName + \" not declared in MyCat schema\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    return route(query);\n} catch (SQLNonTransientException e) {\n    if (e.getMessage().startsWith(\"can't find table define in schema\")) {\n        throw new ConfigurationException(\"Declare table in schema.xml: \" + e.getMessage(), e);\n    }\n    throw e;\n}","preventionTips":["Keep schema.xml and the real MySQL schema in sync; automate config generation from information_schema","Always use consistent table-name casing between SQL and schema.xml","Reload MyCat config (reload @@config) after adding tables","Pin application connections to the intended MyCat logical schema"],"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"}