Skip to content

Commit 3b8b8c9

Browse files
Nikemrnorth
authored andcommitted
Issue 534. Now properly handles command override for MySQL containers
1 parent 4df5012 commit 3b8b8c9

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

modules/jdbc-test/src/test/java/org/testcontainers/junit/SimpleMySQLTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,22 @@ public void testMySQLWithCustomIniFile() throws SQLException {
9494
}
9595
}
9696

97+
@Test
98+
public void testCommandOverride() throws SQLException {
99+
MySQLContainer mysqlCustomConfig = (MySQLContainer) new MySQLContainer().withCommand("mysqld --auto_increment_increment=42");
100+
mysqlCustomConfig.start();
101+
102+
try {
103+
ResultSet resultSet = performQuery(mysqlCustomConfig, "show variables like 'auto_increment_increment'");
104+
String result = resultSet.getString("Value");
105+
106+
assertEquals("Auto increment increment should be overriden by command line", "42", result);
107+
} finally {
108+
mysqlCustomConfig.stop();
109+
}
110+
111+
}
112+
97113
@NonNull
98114
protected ResultSet performQuery(MySQLContainer containerRule, String sql) throws SQLException {
99115
HikariConfig hikariConfig = new HikariConfig();

modules/mysql/src/main/java/org/testcontainers/containers/MySQLContainer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public class MySQLContainer<SELF extends MySQLContainer<SELF>> extends JdbcDatab
2020

2121
public MySQLContainer() {
2222
super(IMAGE + ":latest");
23+
setCommand("mysqld");
2324
}
2425

2526
public MySQLContainer(String dockerImageName) {
@@ -41,7 +42,6 @@ protected void configure() {
4142
addEnv("MYSQL_USER", username);
4243
addEnv("MYSQL_PASSWORD", password);
4344
addEnv("MYSQL_ROOT_PASSWORD", "test");
44-
setCommand("mysqld");
4545
setStartupAttempts(3);
4646
}
4747

0 commit comments

Comments
 (0)