MyCATApache/Mycat-Server · error · SQLNonTransientException

can't find table define of in schema:

Error message

can't find table define of  in schema:

What it means

DruidLockTableParser.statementParse resolves the first table of a LOCK TABLES statement against schema.getTables(). If no TableConfig exists for that (upper-cased) table name in the current schema, it throws SQLNonTransientException reporting the missing table and schema name.

Solutions

  1. Add the missing <table> definition for the table in schema.xml and reload
  2. Verify you connected to the intended MyCat logical schema
  3. Match the table name case with the schema.xml definition (MyCat upper-cases lookups)
  4. Avoid LOCK TABLES on non-configured tables; use application-level locking instead

Example fix

// before (schema.xml has no entry)
LOCK TABLES my_table WRITE;
// after
<table name="MY_TABLE" dataNode="dn1"/> added to schema.xml, then retry LOCK TABLES MY_TABLE WRITE;
Defensive patterns

Strategy: validation

Validate before calling

TableConfig tc = schema.getTables().get(table.toUpperCase()); if (tc == null) throw new IllegalArgumentException("table not in MyCat schema: " + table);

Try / catch

try { lockTables(sql); } catch (SQLNonTransientException e) { if (e.getMessage().startsWith("can't find table define of")) { alertMissingSchemaEntry(extractTable(e)); } else throw e; }

Prevention

When it happens

Trigger: LOCK TABLES statement whose first table is not defined in the MyCat schema.xml for the connected schema (no <table> entry, wrong case, or table only exists physically in MySQL).

Common situations: Locking a global/temp table not declared in schema.xml; case-sensitivity mismatch (MyCat stores table names upper-cased); connecting to the wrong logical schema; table added to MySQL after MyCat config was written.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of MyCATApache/Mycat-Server@65f8d8beb7 (2026-09-11). Data as JSON: /api/errors/f64ea96c850aac76. Report an issue: GitHub.

Appendix: source

Thrown at src/main/java/io/mycat/route/parser/druid/impl/DruidLockTableParser.java:33

import io.mycat.route.parser.druid.MycatSchemaStatVisitor;
import io.mycat.server.parser.ServerParse;
import io.mycat.util.SplitUtil;

/**
 * lock tables [table] [write|read]语句解析器
 * @author songdabin
 */
public class DruidLockTableParser extends DefaultDruidParser implements DruidParser {
	@Override
	public void statementParse(SchemaConfig schema, RouteResultset rrs, SQLStatement stmt)
			throws SQLNonTransientException {
		MySqlLockTableStatement lockTableStat = (MySqlLockTableStatement)stmt;
		String table = lockTableStat.getItems().get(0).getTableSource().toString().toUpperCase();
		TableConfig tableConfig = schema.getTables().get(table);
		if (tableConfig == null) {
			String msg = "can't find table define of " + table + " in schema:" + schema.getName();
			LOGGER.warn(msg);
			throw new SQLNonTransientException(msg);
		}
		LockType lockType = lockTableStat.getItems().get(0).getLockType();
		if (LockType.WRITE != lockType && LockType.READ != lockType) {
			String msg = "lock type must be write or read";
			LOGGER.warn(msg);
			throw new SQLNonTransientException(msg);
		}
		List<String> dataNodes = tableConfig.getDataNodes();
		RouteResultsetNode[] nodes = new RouteResultsetNode[dataNodes.size()];
		for (int i = 0; i < dataNodes.size(); i ++) {
			nodes[i] = new RouteResultsetNode(dataNodes.get(i), ServerParse.LOCK, stmt.toString());
		}
		rrs.setNodes(nodes);
		rrs.setFinishedRoute(true);
	}
	
	@Override
	public void visitorParse(SchemaConfig schema, RouteResultset rrs, SQLStatement stmt, MycatSchemaStatVisitor visitor)

View on GitHub (pinned to 65f8d8beb7)