Software Workshop

java.sql.SQLException The server time zone value 'KST' 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.

위와 같은 에러는 MySQL 서버에 타임존이 지정되어 있지 않기 때문이다.

다음 명령으로 확인 가능하다.

mysql> select @@global.time_zone, @@session.time_zone;
+--------------------+---------------------+
| @@global.time_zone | @@session.time_zone |
+--------------------+---------------------+
| SYSTEM | SYSTEM |
+--------------------+---------------------+

MySQL 서버가 실행되는 디렉토리에 my.cnf를 생성하고 그 안에 타임존을 지정하면 해결된다.

우선 mysqld의 full path를 확인한다.

ps aux | grep mysqld

해당 경로의 mysqld를 통해 my.cnf 설정 파일의 우선순위를 확인한다.

/usr/sbin/mysqld --verbose --help | grep my.cnf
/etc/my.cnf /etc/mysql/my.cnf /usr/local/etc/my.cnf ~/.my.cnf

/etc나 /etc/mysql, /usr/local/etc 또는 홈디렉토리에 my.cnf이 존재하는지 확인해보고 없으면 직접 생성한다.

ls -alF /etc/my.cnf /etc/mysql/my.cnf /usr/local/etc/my.cnf ~/.my.cnf
vi /etc/my.cnf
[mysqld]
default-time-zone='+9:00'

MySQL 서버를 재시작한다. 시스템마다 재시작 방법이 다르니 적절한 명령을 선택해서 수행해야 한다.

mysql.server restart # Official
/etc/init.d/mysqld restart # Linux
service mysqld restart # Linux
brew services restart mysql # macOS, brew

다음 쿼리를 통해 제대로 설정되었는지 확인해본다.

mysql> select now();