개발 잘 하고 싶다 => 알고 쓰자/ERROR(삽질) 모음

[MySQL] time_zone 설정 (그리니치 표준시 -> 한국시간)

장 상 현 2021. 7. 31.

1. config.json 파일 속성 추가

      "timezone": "+09:00",

      "dialectOptions": {
        "charset": "utf8mb4",
        "dateStrings": true,
        "typeCast": true
    }

 

2. MySQL 설정

// Timezone 확인
select @@global.time_zone, @@session.time_zone;

// Timezone 설정
set global time_zone = 'Asia/Seoul';

set session time_zone = 'Asia/Seoul';

 

error 1298 (hy000) Unknown or incorrect time zone 에러시?

 

아래 구문 한줄씩 실행

 

root@~~~~> mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql

 

Enter password: Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it.

 

root@~~~~> mysql_tzinfo_to_sql  /usr/share/zoneinfo/Asia/Seoul KST

 

INSERT INTO time_zone_transition_type (Time_zone_id, Transition_type_id, Offset, Is_DST, Abbreviation) VALUES (@time_zone_id, 0, 30472, 0, 'LMT') ,(@time_zone_id, 1, 30600, 0, 'KST') ,(@time_zone_id, 2, 32400, 0, 'JST') ,(@time_zone_id, 3, 36000, 1, 'KDT') ,(@time_zone_id, 4, 32400, 0, 'KST') ,(@time_zone_id, 5, 34200, 1, 'KDT') ,(@time_zone_id, 6, 36000, 1, 'KDT')

 

root@~~~~> mysql -u 사용자명 -p

mysql > set time_zone = 'Asia/Seoul';

mysql > select @@time_zone;

 

mysql> set time_zone = 'Asia/Seoul'; Query OK, 0 rows affected (0.00 sec)
mysql> select @@time_zone;
+-------------+ 
|@@time_zone |
+-------------+
|  Asia/Seoul  |
+-------------+
1 row in set (0.00 sec)

 

// 이 설정을 영구적으로 반영하기 위해서는 mysqld.cnf 파일의 설정을 기입

root@test ~# > vi /etc/mysql/mysql.conf.d/mysqld.cnf

// 맨 아래서 기입
default-time-zone=Asia/Seoul

 

DB 재시작

 

작업우분투  명령어 CentOS6 명령어 CentOS7 명령어
시작 service mysql start service mysqld start systemctl start mysqld
정지 service mysql stop service mysqld stop systemctl stop mysqld
재시작 service mysql restart service mysqld restart systemctl restart mysqld
상태확인 service mysql status service mysqld status systemctl status mysqld

 

3. DB 컬럼을 타겟으로 새 변수에 담아 리스폰스

댓글