Skip to content

Commit b27316d

Browse files
authored
Set MariaDB user when is not root (#9077)
Currently, setting MYSQL_USER with root won't start the container. Fixes #8846
1 parent 6ef052a commit b27316d

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

modules/mariadb/src/main/java/org/testcontainers/containers/MariaDBContainer.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,10 @@ protected void configure() {
7575
);
7676

7777
addEnv("MYSQL_DATABASE", databaseName);
78-
addEnv("MYSQL_USER", username);
78+
79+
if (!MARIADB_ROOT_USER.equalsIgnoreCase(this.username)) {
80+
addEnv("MYSQL_USER", username);
81+
}
7982
if (password != null && !password.isEmpty()) {
8083
addEnv("MYSQL_PASSWORD", password);
8184
addEnv("MYSQL_ROOT_PASSWORD", password);

modules/mariadb/src/test/java/org/testcontainers/junit/mariadb/SimpleMariaDBTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,18 @@ public void testWithOnlyUserReadableCustomIniFile() throws Exception {
132132
}
133133
}
134134

135+
@Test
136+
public void testEmptyPasswordWithRootUser() throws SQLException {
137+
try (MariaDBContainer<?> mysql = new MariaDBContainer<>("mariadb:11.2.4").withUsername("root")) {
138+
mysql.start();
139+
140+
ResultSet resultSet = performQuery(mysql, "SELECT 1");
141+
int resultSetInt = resultSet.getInt(1);
142+
143+
assertThat(resultSetInt).isEqualTo(1);
144+
}
145+
}
146+
135147
private void assertThatCustomIniFileWasUsed(MariaDBContainer<?> mariadb) throws SQLException {
136148
try (ResultSet resultSet = performQuery(mariadb, "SELECT @@GLOBAL.innodb_max_undo_log_size")) {
137149
long result = resultSet.getLong(1);

0 commit comments

Comments
 (0)