MyCATApache/Mycat-Server · error · ConfigException

dataHost define error,some attributes of this element is…

Error message

dataHost ${dataHost} define error,some attributes of this element is empty: ${nodeHost}

What it means

XMLSchemaLoader throws this ConfigException while parsing a <dataHost> element in schema.xml when a required attribute is blank. Specifically, if the dataHost's host name (nodeHost), url, or user attribute is an empty string, the loader refuses to build a DBHostConfig and aborts configuration loading. MyCat cannot create a connection pool for a backend database host without these identifying attributes.

Solutions

  1. Open schema.xml and locate the dataHost named in the message; fill in the empty attribute (name, url, or user) on the offending writeHost/readHost element
  2. Validate the XML against MyCat's expected dataHost structure before restarting (check every writeHost/readHost has non-empty name, url, user, password)
  3. If using templating/config management, ensure placeholders are substituted and add a build-time check that rejects empty attribute values
  4. Restart MyCat after fixing and confirm the config loads

Example fix

// before (schema.xml)
<writeHost host="" url="jdbc:mysql://10.0.0.1:3306" user="" password="x"/>
// after
<writeHost host="hostM1" url="jdbc:mysql://10.0.0.1:3306" user="mycat" password="x"/>
Defensive patterns

Strategy: validation

Validate before calling

// before starting MyCat, validate schema.xml dataHosts
NodeList hosts = doc.getElementsByTagName("writeHost");
for (int i = 0; i < hosts.getLength(); i++) {
    Element e = (Element) hosts.item(i);
    if (e.getAttribute("name").isEmpty() || e.getAttribute("user").isEmpty() || e.getAttribute("url").isEmpty())
        throw new IllegalStateException("dataHost element with empty attribute at writeHost index " + i);
}

Type guard

boolean hasNonEmpty(Element e, String... attrs) {
    for (String a : attrs) if (e.getAttribute(a) == null || e.getAttribute(a).trim().isEmpty()) return false;
    return true;
}

Try / catch

try {
    schemaLoader.load();
} catch (ConfigException e) {
    LOG.error("schema.xml dataHost config invalid: " + e.getMessage());
    throw new ConfigurationException("Fix schema.xml dataHost attributes before restart", e);
}

Prevention

When it happens

Trigger: Loading mycat schema.xml at startup; a <dataHost> child <writeHost>/<readHost> element has an empty 'name' (host) attribute, or createDBHostConf is called with an empty url or user attribute.

Common situations: Hand-edited schema.xml where a writeHost name="" or user="" was left blank; XML generation tooling emitting empty attributes; copy-paste of a dataHost block where credentials were removed; template placeholders like ${user} never substituted before deployment.

Understand the failure class

Background: "is required", "must be set", "missing required field": configuration validation errors across open-source libraries — this error's family across 36 libraries.

Related errors


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

Appendix: source

Thrown at src/main/java/io/mycat/config/loader/xml/XMLSchemaLoader.java:716

        String nodeHost = node.getAttribute("host");
        String nodeUrl = node.getAttribute("url");
        String user = node.getAttribute("user");
        String password = node.getAttribute("password");
        String usingDecrypt = node.getAttribute("usingDecrypt");
        String checkAliveText = node.getAttribute("checkAlive");
        if (checkAliveText == null)checkAliveText = Boolean.TRUE.toString();
        boolean checkAlive = Boolean.parseBoolean(checkAliveText);

        String passwordEncryty = DecryptUtil.DBHostDecrypt(usingDecrypt, nodeHost, user, password);

        String weightStr = node.getAttribute("weight");
        int weight = "".equals(weightStr) ? PhysicalDBPool.WEIGHT : Integer.parseInt(weightStr);

        String ip = null;
        int port = 0;
        if (empty(nodeHost) || empty(nodeUrl) || empty(user)) {
            throw new ConfigException(
                    "dataHost "
                            + dataHost
                            + " define error,some attributes of this element is empty: "
                            + nodeHost);
        }
        if ("native".equalsIgnoreCase(dbDriver)) {
            int colonIndex = nodeUrl.indexOf(':');
            ip = nodeUrl.substring(0, colonIndex).trim();
            port = Integer.parseInt(nodeUrl.substring(colonIndex + 1).trim());
        } else {
            URI url;
            try {
                url = new URI(nodeUrl.substring(5));
            } catch (Exception e) {
                throw new ConfigException("invalid jdbc url " + nodeUrl + " of " + dataHost);
            }
            ip = url.getHost();
            port = url.getPort();

View on GitHub (pinned to 65f8d8beb7)