프로그래밍

Mysql Server Timezone 설정방법

일태우 2020. 11. 16. 22:32
반응형

Mysql Server Timezone 설정 방법

필자는 Mysql 5.7로 진행하였다.(5.7 이하의 버전이나 이후의 버전도 레퍼런스 확인 결과 비슷함)

 

아래의 명령어로 현재 타임존 확인가능

SELECT @@GLOBAL.time_zone, @@SESSION.time_zone;

 

위와 같이 출력되면 기본 세팅인 것(As the value 'SYSTEM', indicating that the server time zone is the same as the system time zone. - 시스템 시간대를 따라간다고 한다.)

If set to SYSTEM, every MySQL function call that requires a time zone calculation makes a system library call to determine the current system time zone. This call may be protected by a global mutex, resulting in contention.
SYSTEM으로 설정되어 있으면 시스템 라이브러리 호출을 수행하는데, global mutex에 의해 보호된다고함 (global mutex는 동기화 관련 단어임)

 

이제 타임존을 세팅해보자. 아래의 명령어 실행

set global time_zone = 'Asia/Seoul';
set time_zone = 'Asia/Seoul';

 

SQL Error [1298] [HY000]: Unknown or incorrect time zone: 'Asia/Seoul'

위와 같은 에러가 나오는 경우

dev.mysql.com/downloads/timezones.html 에서 버전에 맞는 timezone 정보파일을 받는다. 5.7 이후는 sql로 되어있다.

그리고 해당 파일을 source 명령어로 실행하든, 내용을 직접 복사하여 실행한다.

그리고 다시 위의 타임존 세팅 명령어 실행시 정상 동작한다.

 

DB 서버를 재시작하면 해당 설정이 날아간다.

그러므로 아래의 설정을 적용해준다. 아래 설정시 위의 set 명령어는 해줄 필요 없는듯

my.ini 열기 (mysql server 설정파일 위치 window기준: c:\ProgramData\MySQL\MySQL Server 5.7\my.ini)

[mysqld]
default-time-zone='Asia/Seoul'

mysqld 단락에 위의 코드를 추가하고 재시작

 

참고 : dev.mysql.com/doc/refman/8.0/en/time-zone-support.html

 

MySQL :: MySQL 8.0 Reference Manual :: 5.1.15 MySQL Server Time Zone Support

5.1.15 MySQL Server Time Zone Support This section describes the time zone settings maintained by MySQL, how to load the system tables required for named time support, how to stay current with time zone changes, and how to enable leap-second support. Begi

dev.mysql.com

dev.mysql.com/downloads/timezones.html

 

MySQL :: Time zone description tables

Please don't use this package if your system includes zoneinfo files (e.g. Linux, FreeBSD, Sun Solaris) Please generate the mysql.time_zone* tables from those files using the mysql_tzinfo_to_sql utility instead! (Otherwise you may cause a difference in dat

dev.mysql.com

 

반응형