user3357926
user3357926

Reputation: 1137

How to configure time zone in Testcontainers MySQL

May I know how do we configure the time zone in Testcontainers MySQL during testing? Also, how can we verify the time zone in Testcontainers MySQL?

Upvotes: 3

Views: 4494

Answers (2)

VolkanT
VolkanT

Reputation: 634

You may use the jdbc connection string to make the MySQL testcontainer use your "cnf" file, which sets the timezone

jdbc:tc:mysql:5.7.34://hostname/databasename?TC_MY_CNF=mysql_conf_override

And under mysql_conf_override folder you need to have a my.cnf file with the following content:

[mysqld]
default-time-zone = "Europe/Istanbul"

Finally, you may check the TZ in your testcontainer via

SELECT @@GLOBAL.time_zone, @@SESSION.time_zone;

after connecting to the container:

mysql -u root -ptest

Upvotes: 1

Luan Kevin Ferreira
Luan Kevin Ferreira

Reputation: 1390

It's possible to add an init script setting the timezone:

new MySQLContainer("mysql:8.0.32").withInitScript("init.sql");

Then you add to your init.sql file the following command:

-- Here you can put other SQL commands

SET time_zone =  'UTC';

Upvotes: 0

Related Questions