MyCATApache/Mycat-Server · critical · io.mycat.config.ConfigException

dataHost not exists

Error message

dataHost not exists {dataHost}

What it means

During initDataNodes, each dataNode references a dataHost by name; ConfigInitializer looks the host up in the already-parsed dataHosts map and throws ConfigException('dataHost not exists ...') when the reference cannot be resolved.

Solutions

  1. Add or fix a <dataHost name="..."> entry whose name exactly matches the dataNode's dataHost attribute
  2. Check for typos/case differences between dataNode.dataHost and dataHost.name
  3. If config is split across files, ensure the dataHost is actually loaded by the ConfigLoader

Example fix

// before (schema.xml)
<dataNode name="dn1" dataHost="host1" database="db" />
// after (add matching host or fix reference)
<dataHost name="host1"> ... </dataHost>
<dataNode name="dn1" dataHost="host1" database="db" />
Defensive patterns

Strategy: validation

Validate before calling

Set<String> hostNames = dataHosts.keySet();
for (DataNodeConfig n : dataNodes) {
    if (!hostNames.contains(n.getDataHost()))
        throw new IllegalArgumentException("dataHost not exists: " + n.getDataHost());
}

Try / catch

try {
    initConfig();
} catch (ConfigException e) {
    if (e.getMessage().startsWith("dataHost not exists")) {
        // fix schema.xml reference before retrying startup
    }
}

Prevention

When it happens

Trigger: A <dataNode> in schema.xml sets a dataHost attribute that has no matching <dataHost> name (typo, missing dataHost block, or dataHost defined in a file not loaded).

Common situations: Copy-pasting dataNode definitions without copying the corresponding dataHost; renaming a dataHost but not updating dataNode references; XML config split across files with only one loaded.

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/dd90606a270f0a47. Report an issue: GitHub.

Appendix: source

Thrown at src/main/java/io/mycat/config/ConfigInitializer.java:333

			PhysicalDatasource[] readSources = createDataSource(conf, name,
					dbType, dbDriver, entry.getValue(), true);
			readSourcesMap.put(entry.getKey(), readSources);
		}
		PhysicalDBPool pool = new PhysicalDBPool(conf.getName(), conf,
				writeSources, readSourcesMap, conf.getBalance(),
				conf.getWriteType());
		pool.setSlaveIDs(conf.getSlaveIDs());
		return pool;
	}

	private Map<String, PhysicalDBNode> initDataNodes(ConfigLoader configLoader) {
		Map<String, DataNodeConfig> nodeConfs = configLoader.getDataNodes();
		Map<String, PhysicalDBNode> nodes = new HashMap<String, PhysicalDBNode>(
				nodeConfs.size());
		for (DataNodeConfig conf : nodeConfs.values()) {
			PhysicalDBPool pool = this.dataHosts.get(conf.getDataHost());
			if (pool == null) {
				throw new ConfigException("dataHost not exists "
						+ conf.getDataHost());

			}
			PhysicalDBNode dataNode = new PhysicalDBNode(conf.getName(),
					conf.getDatabase(), pool);
			nodes.put(dataNode.getName(), dataNode);
		}
		return nodes;
	}

}

View on GitHub (pinned to 65f8d8beb7)