javamysqlmysql-connectortomcat9tomcat-jdbc

mysql-connector-java-8.0.12 : getting error for 'Malay Peninsula Standard Time' server time zone


We recently upgraded MySQL from 5.6 to 8. So, as per upgrade instructions,using mysql-java-connector(8.0.12) and new driver class name i.e com.mysql.cj.jdbc.Driver in database url. But Getting below error only for this time zone 'Malay Peninsula Standard Time'

java.sql.SQLException: Cannot create PoolableConnectionFactory (The server time zone value 'Malay Peninsula Standard Time' 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.) Related cause: org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'dynamicEntityManagerFactory': FactoryBean which is currently in creation returned null from getObject at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:378) ............... .............. Caused by: java.sql.SQLException: The server time zone value 'Malay Peninsula Standard Time' 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. at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)

using below configuration to create connections in tomcat context.xml

<Resource auth="Container" driverClassName="com.mysql.cj.jdbc.Driver" factory="com.grc.common.EncryptedDataSourceFactory" maxActive="100" maxIdle="30" maxWait="10000" minEvictableIdleTimeMillis="30000" minIdle="10" name="jdbc/TestDB" password="0df9f21ee02a561fa39f18f5c7581061" removeAbandoned="true" removeAbandonedTimeout="180" testOnBorrow="true" testOnReturn="false" testWhileIdle="true" timeBetweenEvictionRunsMillis="30000" type="javax.sql.DataSource" url="jdbc:mysql://127.0.0.1:3306/production1?useSSL=false" username="root" validationInterval="30000" validationQuery="SELECT 1"/>

Also, tried with serverTimezone parameter like below, but no luck.

<Resource auth="Container" driverClassName="com.mysql.cj.jdbc.Driver" factory="com.grc.common.EncryptedDataSourceFactory" maxActive="100" maxIdle="30" maxWait="10000" minEvictableIdleTimeMillis="30000" minIdle="10" name="jdbc/TestDB" password="0df9f21ee02a561fa39f18f5c7581061" removeAbandoned="true" removeAbandonedTimeout="180" testOnBorrow="true" testOnReturn="false" testWhileIdle="true" timeBetweenEvictionRunsMillis="30000" type="javax.sql.DataSource" url="jdbc:mysql://127.0.0.1:3306/production1?useSSL=false&amp;serverTimezone=Malay Peninsula Standard Time" username="root" validationInterval="30000" validationQuery="SELECT 1"/>

Solution

  • I resolved myself without changing any registry at OS level. This may help others.

    Getting this error since Time zone name with 'Malay Peninsula Standard Time' is not available in MySQL. So as instructed in this MySQL Documenation, downloaded timezone_2018e_posix_sql.zip from this MySQL Timezones and loaded into MySQL database as instructed. After that added below configuration in my.ini file and restarted the server.

    default_time_zone=Asia/Singapore