[MySQL] jdbc로 MySQL 접속시 timezone 에러 – “The server time zone value ‘XXXX’ is unrecognized or represents more than one time zone.”이라고 뜰때

급하게 jsp로 웹사이트를 만들어야 되서.. 여기저기 찾아가며 하고 있는데.. DB접속부터 안된다.

일단 jsp에서 stacktrace를 찍어보니.. 다음과 같은 메시지가 보이는데..

The server time zone value ‘ XXXX’ is unrecognized or represents more than one time zone.

중간에 XXXX자리는 캐릭터셋이 안맞는지 깨져서 이상한 글씨로 보인다..

대충보니 msyql에 time zone이 안맞거나 인식을 못해서 그러는것 같은데..
역시나 구글링을 해본다.

방법1.

접속할때 jdbc url에 timezone을 지정한다. (보통 jsp에서 커넥션 생성할때 하거나, DB pool을 쓸경우 config.xml 에서 설정

jdbc:mysql://ip:port/testdb?characterEncoding=UTF-8&serverTimezone=UTC

혹시 The reference to entity “serverTimezone” must end with the ‘;’ delimiter.  에러가 발생할 경우 & 대신에 &  사용

jdbc:mysql://ip:port/testdb?characterEncoding=UTF-8&serverTimezone=UTC

방법2.

MySQL에서 타임존을 추가한다.

방법 2-1. mysql config파일의 [mysqld] 섹센에 다음과 같이 추가

default_time_zone='+03:00'

mysql 재시작

$ service mysql restart

방법 2-2. mysql 서버의 타임존을 “Asia/Seoul”로 지정

mysql 설정확인

mysql> SELECT @@global.time_zone, @@session.time_zone;
+--------------------+---------------------+
| @@global.time_zone | @@session.time_zone |
+--------------------+---------------------+
| SYSTEM             | SYSTEM              |
+--------------------+---------------------+
1 row in set (0.00 sec)

이상태에서는 mysql db의 time_zone과 time_zone_name 2개의 테이블이 비어있는 상태이며, SET time_zone = ‘Asia/Seoul’ 명령도 에러 발생

시스템의 타임존 정보를 mysql에 입력

[root@debian ~]# ./bin/mysql_tzinfo_to_sql /usr/share/zoneinfo | ./bin/mysql -D mysql -u root -p
Enter password: 
Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.

설정 파일 변경

[root@debian ~]# vi /etc/my.cnf

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

mysql 재시작 및 확인

[root@debian ~]# service mysql restart

mysql> SELECT @@global.time_zone, @@session.time_zone;
+--------------------+---------------------+
| @@global.time_zone | @@session.time_zone |
+--------------------+---------------------+
| Asia/Seoul         | Asia/Seoul          |
+--------------------+---------------------+
1 row in set (0.00 sec)

Loading

댓글 남기기