How to configure time zone in Testcontainers MySQL

Viewed 717

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?

1 Answers

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
Related