{"record":{"id":"1582f11726f0dc99","repo":"testcontainers/testcontainers-java","slug":"empty-password-can-be-used-only-with-the-root-user","errorCode":null,"errorMessage":"Empty password can be used only with the root user","messagePattern":"Empty password can be used only with the root user","errorType":"exception","errorClass":"ContainerLaunchException","httpStatus":null,"severity":"error","filePath":"modules/mariadb/src/main/java/org/testcontainers/containers/MariaDBContainer.java","lineNumber":83,"sourceCode":"        optionallyMapResourceParameterAsVolume(\n            MY_CNF_CONFIG_OVERRIDE_PARAM_NAME,\n            \"/etc/mysql/conf.d\",\n            \"mariadb-default-conf\",\n            Transferable.DEFAULT_DIR_MODE\n        );\n\n        addEnv(\"MYSQL_DATABASE\", databaseName);\n\n        if (!MARIADB_ROOT_USER.equalsIgnoreCase(this.username)) {\n            addEnv(\"MYSQL_USER\", username);\n        }\n        if (password != null && !password.isEmpty()) {\n            addEnv(\"MYSQL_PASSWORD\", password);\n            addEnv(\"MYSQL_ROOT_PASSWORD\", password);\n        } else if (MARIADB_ROOT_USER.equalsIgnoreCase(username)) {\n            addEnv(\"MYSQL_ALLOW_EMPTY_PASSWORD\", \"yes\");\n        } else {\n            throw new ContainerLaunchException(\"Empty password can be used only with the root user\");\n        }\n        setStartupAttempts(3);\n    }\n\n    @Override\n    public String getDriverClassName() {\n        return \"org.mariadb.jdbc.Driver\";\n    }\n\n    @Override\n    public String getJdbcUrl() {\n        String additionalUrlParams = constructUrlParameters(\"?\", \"&\");\n        return (\n            \"jdbc:mariadb://\" + getHost() + \":\" + getMappedPort(MARIADB_PORT) + \"/\" + databaseName + additionalUrlParams\n        );\n    }\n\n    @Override","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/testcontainers/testcontainers-java/blob/8e549514e3f01c57d70546fbb8599d138f3903e5/modules/mariadb/src/main/java/org/testcontainers/containers/MariaDBContainer.java#L65-L101","documentation":"MariaDBContainer.configure() validates credentials when building the container environment. If no password is set, an empty-password database is only allowed for the root user (MYSQL_ALLOW_EMPTY_PASSWORD). For any other username it throws ContainerLaunchException, because MariaDB images refuse empty passwords for non-root users.","triggerScenarios":"Constructing new MariaDBContainer(...) without calling withPassword(...) (or calling withPassword(\"\") ) while withUsername(...) is set to a non-root user such as 'test', then starting the container.","commonSituations":"Copy-pasted container setup where the username was customized but the password line was dropped; relying on a default empty password after a library version change; YAML/properties-driven config where the password key is missing.","solutions":["Call .withPassword(\"some-password\") on the container builder","Or use the root user via .withUsername(\"root\") if you intentionally want an empty password","Or set the password from configuration/properties instead of hardcoding an empty value"],"exampleFix":"// before\nMariaDBContainer mariadb = new MariaDBContainer(\"mariadb:10.6\")\n    .withUsername(\"appuser\"); // empty password, non-root -> throws\n// after\nMariaDBContainer mariadb = new MariaDBContainer(\"mariadb:10.6\")\n    .withUsername(\"appuser\")\n    .withPassword(\"testpassword\");","handlingStrategy":"validation","validationCode":"// before start()\nObjects.requireNonNull(container.getUsername());\nif (container.getUsername() != null && !\"root\".equalsIgnoreCase(container.getUsername())\n        && (password == null || password.isEmpty())) {\n    throw new IllegalArgumentException(\"MariaDBContainer requires a password for non-root users\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    mariadb.start();\n} catch (ContainerLaunchException e) {\n    if (e.getMessage().contains(\"Empty password\")) {\n        throw new IllegalStateException(\"Set withPassword() or use username 'root'\", e);\n    }\n    throw e;\n}","preventionTips":["Always pair withUsername() with withPassword() in shared fixtures","Never pass empty strings to withPassword()","Centralize container creation in a factory that enforces credentials"],"tags":["mariadb","database","testcontainers","configuration"],"backgroundTag":"missing-credentials","analyzedSha":"8e549514e3f01c57d70546fbb8599d138f3903e5","analyzedAt":"2026-09-12T14:56:41.227Z","contentChangedAt":"2026-09-12T14:56:41.227Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}