有一种方法可以设置全局变量:explicit_defaults_for_timestamp=true,使用测试停靠容器?
我的单元测试中有以下代码:
@Container
public static final MySQLContainer<?> mySQLContainer = new MySQLContainer<>()
.withDatabaseName("test")
.withPassword("123")
.withUsername("test")
.withExposedPorts(3306)
.withInitScript("database-creation-scripts/mysql-install.sql");容器启动,但默认值为false:
mysql> SHOW GLOBAL VARIABLES LIKE '%timestamp%';
+---------------------------------+-------+
| Variable_name | Value |
+---------------------------------+-------+
| explicit_defaults_for_timestamp | OFF |
| log_timestamps | UTC |
+---------------------------------+-------+
2 rows in set (0.00 sec)我找不到在MySQLContainer中设置全局变量的方法.with[...]。
发布于 2020-07-05 00:48:44
因为您可以使用如下命令行标志将配置参数传递到MySQL停靠容器:
docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:5.7 --explicit_defaults_for_timestamp您可以使用`.withCommand()将其镜像到测试容器中:
@Container
public static final MySQLContainer<?> mySQLContainer = new MySQLContainer<>()
.withDatabaseName("test")
.withPassword("123")
.withUsername("test")
.withExposedPorts(3306)
.withInitScript("database-creation-scripts/mysql-install.sql")
.withCommand("--explicit_defaults_for_timestamp");https://stackoverflow.com/questions/62722053
复制相似问题