CATCHV Blog

mysql_tzinfo_to_sql 본문

Database/MySQL

mysql_tzinfo_to_sql

catchv 2022. 11. 17. 11:43
반응형

1. mysql_tzinfo_to_sql

 

mysql_tzinfo_to_sql 프로그램은 mysql에서 사용하는 time zone 을 설정 할 수 있는 정보를 mysql server에 제공합니다. 기본값은 시스템 타임 존(system_time_zone)을 따라가는 SYSTEM으로 설정이 되어 있습니다.

 

mysql> show VARIABLES LIKE '%time_zone%';
+------------------+--------+
| Variable_name    | Value  |
+------------------+--------+
| system_time_zone | KST    |
| time_zone        | SYSTEM |
+------------------+--------+

서버의 time_zone은 서버에서 사용되는 시간 NOW(), CURRENT_DATE() 등의 시간 함수의 시간에 영향을 줍니다.

AWS Aurora Mysql은 시스템 시간이 UTC 고정이고 변경이 불가능합니다. 이런 경우 한국시간으로 명시적으로 지정하여 mysql에서 사용되는 시간을 지정할 수 있습니다. 

mysql> SET GLOBAL time_zone = 'Asia/Seoul';
ERROR 1298 (HY000): Unknown or incorrect time zone: 'Asia/Seoul'

하지만 mysql을 dnf로 설치시 mysql.time_zone 테이블에 해당 정보가 존재하지 않아 설정이 불가능합니다. 이런 경우 linux의 시간 정보를 이용하여 mysql에서 사용 할 수 있는 time_zone 정보를 넣을 수 있는데 이때 사용하는 프로그램이 mysql_tzinfo_to_sql  입니다.

1) rocky linux 9.x 의 timezone 경로

[root@37bfcb726d10 zoneinfo]# pwd
/usr/share/zoneinfo
[root@37bfcb726d10 zoneinfo]# ls
Africa      Canada   Factory    Iceland    MST7MDT   ROC        Zulu
America     Chile    GB         Indian     Mexico    ROK        iso3166.tab
Antarctica  Cuba     GB-Eire    Iran       NZ        Singapore  leapseconds
Arctic      EET      GMT        Israel     NZ-CHAT   Turkey     posix
Asia        EST      GMT+0      Jamaica    Navajo    UCT        posixrules
Atlantic    EST5EDT  GMT-0      Japan      PRC       US         right
Australia   Egypt    GMT0       Kwajalein  PST8PDT   UTC        tzdata.zi
Brazil      Eire     Greenwich  Libya      Pacific   Universal  zone.tab
CET         Etc      HST        MET        Poland    W-SU       zone1970.tab
CST6CDT     Europe   Hongkong   MST        Portugal  WET
[root@37bfcb726d10 zoneinfo]#

2) mysql에 timezone 정보 입력

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/leapseconds' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/tzdata.zi' 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.

3) timezone정보 확인

mysql> SELECT * FROM mysql.time_zone_name LIMIT 10;
+--------------------+--------------+
| Name               | Time_zone_id |
+--------------------+--------------+
| Africa/Abidjan     |            1 |
| Africa/Accra       |            2 |
| Africa/Addis_Ababa |            3 |
| Africa/Algiers     |            4 |
| Africa/Asmara      |            5 |
| Africa/Asmera      |            6 |
| Africa/Bamako      |            7 |
| Africa/Bangui      |            8 |
| Africa/Banjul      |            9 |
| Africa/Bissau      |           10 |
+--------------------+--------------+
10 rows in set (0.00 sec)

4) time_zone 설정

mysql> SET GLOBAL time_zone = 'Asia/Seoul';
Query OK, 0 rows affected (0.00 sec)

5) timezone 다운로드

만약 linux의 timezone 정보가 없거나 최신이 아닌 경우 아래의 경로에서 최신 정보를 다운 받아 입력 할 수 있습니다.

https://dev.mysql.com/downloads/timezones.html

 

반응형

'Database > MySQL' 카테고리의 다른 글

mysqlcheck  (0) 2022.11.18
mysqladmin  (0) 2022.11.17
mysql_secure_installation  (0) 2022.11.17
mysql 8.x - mysql_config_editor  (0) 2022.11.16
mysql 8.x 관련 스크립트 파일  (0) 2022.11.16
Comments