๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Database·SQL

[MySQL] The server time zone value is unrecognized or represents more than one time zone ์—๋Ÿฌ ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•

by Leica 2020. 2. 9.
๋ฐ˜์‘ํ˜•

The server time zone value is unrecognized or represents more than one time zone ์—๋Ÿฌ ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•

Java์—์„œ ๋กœ์ปฌ MySQL ์„œ๋ฒ„์— ์—ฐ๊ฒฐํ•˜๋˜ ์ค‘ ์•„๋ž˜์™€ ๊ฐ™์€ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ–ˆ๋‹ค.

 

java.sql.SQLException: The server time zone value is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.

 

ํ•ด์„ํ•˜๋ฉด '์„œ๋ฒ„ ์‹œ๊ฐ„๋Œ€ ๊ฐ’์ด ์ธ์‹๋˜์ง€ ์•Š๊ฑฐ๋‚˜ ๋‘˜ ์ด์ƒ์˜ ์‹œ๊ฐ„๋Œ€๋ฅผ ๋‚˜ํƒ€๋‚ธ๋‹ค. ์„œ๋ฒ„ ๋˜๋Š” JDBC ๋“œ๋ผ์ด๋ฒ„(serverTimezone configuration property๋ฅผ ํ†ตํ•ด)๋ฅผ ๊ตฌ์„ฑํ•˜์—ฌ ๋” ๊ตฌ์ฒด์ ์ธ ํ‘œ์ค€ ์‹œ๊ฐ„๋Œ€ ๊ฐ’์„ ์‚ฌ์šฉํ•ด์•ผํ•œ๋‹ค.' ๋ผ๋Š” ๋œป์ด๋‹ค.

 

ํ˜„์žฌ MySQL์˜ GLOBAL(์ „์—ญ) ๋ฐ SESSION time zone(์‹œ๊ฐ„๋Œ€) ๊ฐ’์€ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

 

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

'SYSTEM'์€ MySQL ์„œ๋ฒ„ ์‹œ๊ฐ„๋Œ€๊ฐ€ ์‹œ์Šคํ…œ ์‹œ๊ฐ„๋Œ€์™€ ๋™์ผํ•œ ๊ฒƒ์œผ๋กœ์จ ๊ตฌ์ฒด์ ์ธ ๋ช…์‹œ๊ฐ€ ๋˜์–ด์žˆ์ง€ ์•Š์Œ์„ ๋‚˜ํƒ€๋‚ธ๋‹ค. ์ด ๋•Œ๋ฌธ์— Exception์ด ๋ฐœ์ƒํ•œ ๊ฒƒ์ด๋‹ค. ์•„๋ž˜์˜ ๋ฐฉ๋ฒ• ์ค‘ ํ•˜๋‚˜๋ฅผ ํƒํ•˜์—ฌ ์‹œ๊ฐ„๋Œ€๋ฅผ ์ง€์ •ํ•˜๋ฉด ํ•ด๊ฒฐ๋œ๋‹ค.

 

๋ฐฉ๋ฒ• 1: SET Statement ์‹คํ–‰

์ด ๋ฐฉ๋ฒ•์€ ๋Ÿฐํƒ€์ž„์— ์„œ๋ฒ„ ์‹œ๊ฐ„๋Œ€ ๊ฐ’์„ ์„ค์ •ํ•  ์ˆ˜ ์žˆ๋‹ค. ์‹œ๊ฐ„๋Œ€๋Š” UTC๋กœ๋ถ€ํ„ฐ์˜ ์˜คํ”„์…‹์„ ๋‚˜ํƒ€๋‚ด๋Š” ๋ฌธ์ž์—ด๋กœ ์ง€์ •ํ•  ์ˆ˜ ์žˆ๋‹ค. UTC๋กœ ์ง€์ •ํ•˜๋ ค๋ฉด '+0:00'์œผ๋กœ, KST๋กœ ์ง€์ •ํ•˜๋ ค๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์ด '+9:00'์œผ๋กœ ์ง€์ •ํ•ด์ฃผ๋ฉด ๋œ๋‹ค.

 

SET GLOBAL time_zone = '+9:00';    # ๊ถŒํ•œ ํ•„์š”
SET time_zone = '+9:00';

 

SET GLOBAL time_zone์€ ์‹คํ–‰ํ•˜๋ ค๋ฉด ๊ถŒํ•œ์ด ํ•„์š”ํ•˜๋‹ค.

 

๋ฐฉ๋ฒ• 2: default-time-zone ์˜ต์…˜ ์ง€์ •

์ด ๋ฐฉ๋ฒ•์€ ์„œ๋ฒ„ ์žฌ๊ธฐ๋™์ด ํ•„์š”ํ•˜๋‹ค. ์„œ๋ฒ„ ๊ตฌ๋™ ์‹œ ๋ช…๋ น์ค„์— --default-time-zone ์˜ต์…˜์„ ์‚ฌ์šฉํ•˜๊ฑฐ๋‚˜ my.ini ํŒŒ์ผ์˜ [mysqld]์— ์ถ”๊ฐ€ํ•œ๋‹ค.

 

my.ini์— default-time-zone ์˜ต์…˜ ์ถ”๊ฐ€


my.ini ์ˆ˜์ • ํ›„ MySQL ์„œ๋ฒ„๋ฅผ ์žฌ๊ธฐ๋™ํ•œ๋‹ค.

 

๋ฐฉ๋ฒ•1 ๋˜๋Š” ๋ฐฉ๋ฒ•2๋ฅผ ์ ์šฉํ•˜๋ฉด ์•„๋ž˜์™€ ๊ฐ™์ด MySQL ์„œ๋ฒ„ ์‹œ๊ฐ„๋Œ€๊ฐ€ ๋ณ€๊ฒฝ๋˜๋ฉฐ ์ž๋ฐ”์—์„œ ์ •์ƒ์ ์œผ๋กœ ์—ฐ๊ฒฐํ•  ์ˆ˜ ์žˆ๋‹ค.

 

๋ฐฉ๋ฒ•1 ๋˜๋Š” ๋ฐฉ๋ฒ•2 ์ ์šฉ ํ›„ ์„œ๋ฒ„ ์‹œ๊ฐ„๋Œ€

 

๋ฐฉ๋ฒ• 3: JDBC Properties ์„ค์ •

์ด ๋ฐฉ๋ฒ•์€ MySQL ์„œ๋ฒ„์™€ ์ƒ๊ด€ ์—†์ด JDBC์™€ ์—ฐ๊ฒฐ ์‹œ ์†์„ฑ๊ฐ’์„ ์„ค์ •ํ•ด์„œ ์‹œ๊ฐ„๋Œ€๋ฅผ override(์žฌ์ •์˜)ํ•˜๋Š” ๋ฐฉ๋ฒ•์ด๋‹ค. MySQL ์„œ๋ฒ„ ์‹œ๊ฐ„๋Œ€๊ฐ€ ๋ณ€๊ฒฝ๋˜์ง€ ์•Š๋Š”๋‹ค.

 

์—ฐ๊ฒฐ ๋ฉ”์†Œ๋“œ๋ฅผ ํ˜ธ์ถœํ•  ๋•Œ serverTimezone property๋ฅผ ๋„˜๊ธฐ๊ฑฐ๋‚˜ JDBC URL์— ์ถ”๊ฐ€ํ•œ๋‹ค.

๋‹จ MySQL ์„œ๋ฒ„์˜ ์‹œ๊ฐ„๋Œ€๋ฅผ ์ง€์ •ํ•˜๋Š” ๊ฒƒ๊ณผ ๋‹ฌ๋ฆฌ ํ•œ๊ตญ ์‹œ๊ฐ„์€ Asia/Seoul ๊ฐ’์„ ์ง€์ •ํ•ด์•ผ ํ•œ๋‹ค.

 

properties.setProperty("serverTimezone", "Asia/Seoul");
try {
    DriverManager.registerDriver(new com.mysql.cj.jdbc.Driver());
    conn = DriverManager.getConnection("jdbc:mysql://localhost:3307/knou", properties);

<Properties ๊ฐ์ฒด์— ๋‹ด์•„ ๋„˜๊ฒจ์„œ ์„ค์ •>

 

try {
    DriverManager.registerDriver(new com.mysql.cj.jdbc.Driver());
    conn = DriverManager.getConnection("jdbc:mysql://localhost:3307/knou?serverTimezone=Asia/Seoul", properties);

<JDBC URL์— ๋ถ™์—ฌ์„œ ์„ค์ •>

 

์ฐธ๊ณ ๋กœ serverTimezone์€ ์„œ๋ฒ„์˜ ํ‘œ์ค€ ์‹œ๊ฐ„๋Œ€๊ฐ€ Java ํ‘œ์ค€ ์‹œ๊ฐ„๋Œ€๋กœ ๋งคํ•‘๋˜์ง€ ์•Š์„ ๋•Œ ์‚ฌ์šฉ๋˜๋Š” ์†์„ฑ์ด๋‹ค.

 

References

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

https://offbyone.tistory.com/318

๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€