MyCATApache/Mycat-Server · error · ConfigException

user duplicated!

Error message

user ${name} duplicated!

What it means

XMLServerLoader.loadUsers iterates <user> elements in server.xml and stores them keyed by the name attribute. If a second <user> reuses a name already in the users map, it throws this ConfigException because user names must be unique — each name identifies exactly one account with its own password and privileges. Startup aborts.

Solutions

  1. Search server.xml for duplicate <user name="..."> elements and rename the extra account to a unique name (then update client connection strings that use it)
  2. Remove genuinely redundant duplicate user blocks
  3. If duplicates come from config merging tooling, deduplicate users before deployment and add a uniqueness check
  4. Restart MyCat and confirm server.xml loads

Example fix

// before
<user name="root">...</user>
<user name="root">...</user>
// after
<user name="root">...</user>
<user name="app">...</user>
Defensive patterns

Strategy: validation

Validate before calling

// detect duplicate user names in server.xml
Set<String> seen = new HashSet<>();
NodeList us = doc.getElementsByTagName("user");
for (int i = 0; i < us.getLength(); i++) {
    String n = ((Element) us.item(i)).getAttribute("name");
    if (!seen.add(n)) throw new IllegalStateException("Duplicate user: " + n);
}

Type guard

null

Try / catch

try {
    serverLoader.load();
} catch (ConfigException e) {
    LOG.error("Duplicate user name in server.xml: " + e.getMessage());
    throw new ConfigurationException("User names must be unique", e);
}

Prevention

When it happens

Trigger: Loading server.xml where two <user name="root"> (or any repeated name) elements exist; duplicates may also come from merged or included server.xml fragments.

Common situations: Copy-pasting a user block to create a second account and forgetting to rename it; merging environment configs that both define 'root'; generated configs re-emitting the same user.

Understand the failure class

Background: Conflicting config options: "cannot be used together" — configuration validation errors across open-source libraries — this error's family across 162 libraries.

Related errors


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

Appendix: source

Thrown at src/main/java/io/mycat/config/loader/xml/XMLServerLoader.java:244

				}

				String readOnly = (String) props.get("readOnly");
				if (null != readOnly) {
					user.setReadOnly(Boolean.parseBoolean(readOnly));
				}


				String schemas = (String) props.get("schemas");
                if (schemas != null) {
                    String[] strArray = SplitUtil.split(schemas, ',', true);
                    user.setSchemas(new HashSet<String>(Arrays.asList(strArray)));
                }

                //加载用户 DML 权限
                loadPrivileges(user, e);

                if (users.containsKey(name)) {
                    throw new ConfigException("user " + name + " duplicated!");
                }
                users.put(name, user);
            }
        }
    }

    private void loadPrivileges(UserConfig userConfig, Element node) {

    	UserPrivilegesConfig privilegesConfig = new UserPrivilegesConfig();

    	NodeList privilegesNodes = node.getElementsByTagName("privileges");
    	int privilegesNodesLength = privilegesNodes.getLength();
		for (int i = 0; i < privilegesNodesLength; ++i) {
			Element privilegesNode = (Element) privilegesNodes.item(i);
			String check = privilegesNode.getAttribute("check");
         	if (null != check) {
         		privilegesConfig.setCheck(Boolean.valueOf(check));
			}

View on GitHub (pinned to 65f8d8beb7)