본문 바로가기
MySql

MySQL mysql Docker 컨테이너에 시간대 구성

by 베이스 공부 2020. 10. 19.
반응형

mysql 5.7 도커 컨테이너가 있습니다. mysql 명령을 실행할 때 :

SELECT now();


mysqldb:
    image: mysql:5.7.21
    container_name: mysql_container
    ports:
      - "3306:3306"
    volumes:
      - ./.docker/etc/mysql/custom.cnf:/etc/mysql/conf.d/custom.cnf

컨테이너 내부의 파일을 탐색 할 때 custom.cnf 파일이 있습니다. 이 파일에서 다음과 같은 솔루션으로 찾은 몇 가지 방법을 시도했습니다.

[mysqld]
default_time_zone='Europe/Sofia'

또는 1 년에 두 번 (여름 / 겨울) 영역을 변경해야하므로 덜 우아한 타협 솔루션 :

[mysqld]
default_time_zone='+03:00'

그러나 아무것도 작동하지 않습니다. 잘못된 구성을 넣으려고하면 아무 일도 일어나지 않기 때문에이 파일은 mysql에 의해 전혀로드되지 않습니다 (컨테이너가 정상적으로 시작됨). 그것에 대한 제안이 있습니까?

 

해결 방법

 

따라서이 경우 Dockerfile 을 사용하고 아래와 같이 처리해야합니다.

FROM mysql:5.7.21
RUN echo "USE mysql;" > /docker-entrypoint-initdb.d/timezones.sql &&  mysql_tzinfo_to_sql /usr/share/zoneinfo >> /docker-entrypoint-initdb.d/timezones.sql

이렇게하면 mysql 컨테이너가로드 될 때 모든 시간대 정보가로드됩니다. 이제 환경 변수를 사용하여 사용할 수 있습니다.

환경 변수

mysqldb:
    #image: mysql:5.7.21
    build: .
    #container_name: mysql_container
    ports:
      - "3306:3306"
    environment:
      - MYSQL_ROOT_PASSWORD=root
      - TZ=Europe/Sofia

구성 파일과 함께 사용하는 것은 문제입니다. DB를 시작하면 오류가 발생합니다.

mysqldb_1  | 2018-04-24T12:29:43.169214Z 0 [Warning] InnoDB: New log files created, LSN=45790
mysqldb_1  | 2018-04-24T12:29:43.215187Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
mysqldb_1  | 2018-04-24T12:29:43.281229Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 2a87fec6-47bb-11e8-9f1e-0242ac110002.
mysqldb_1  | 2018-04-24T12:29:43.284010Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
mysqldb_1  | 2018-04-24T12:29:43.284404Z 0 [ERROR] Fatal error: Illegal or unknown default time zone 'Europe/Sofia'
mysqldb_1  | 2018-04-24T12:29:43.284567Z 0 [ERROR] Aborting

이는 이미로드 된 시간대가 필요하기 때문입니다. 이것을 고칠 수도 있지만 너무 번거 롭습니다. 컨테이너가 시작될 때 시간대가 이미 설정되어 있음을 의미하기 때문에 환경 변수 만 사용하겠습니다.


 

참조 페이지 https://stackoverflow.com/questions/49959601

 

 

반응형

댓글