How to init mysql in docker with correct time_zone_name table?

Viewed 23

Is there anyway to init MySQL with specific tables for time zone?

I am trying to use MySQL 5.7 on docker with image mysql:5.7 and Asia/Hong_Kong is used as timezone name in the application. But on the default table mysql.time_zone_name built on the docker image only contains:

  • posix/HongKong
  • right/Asia/Hong_Kong
  • right/Hongkong

I understood that I could manually Populating the Time Zone Tables with mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql or through given SQL on https://dev.mysql.com/downloads/timezones.html

As I am using default_time_zone='Asia/Hong_Kong' in mysqld in my.cnf, this would be a fatal error as Asia/Hong_Kong do not exist at that moment.

1 Answers

You should set ENV in your Docker-Compose file

services:
  db:
    image: mysql:5.7
    ports:
      - "3306:3306"
    environment:
      - MYSQL_ROOT_PASSWORD=docker
      - TZ=Asia/Hongkong
    command: ['mysqld', '--character-set-server=utf8mb4', '--default-time-zone=+09:00']
Related