Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL JDBC Driver 5.1.33 - Time Zone Issue

Some background:

I have a Java 1.6 webapp running on Tomcat 7. The database is MySQL 5.5. Previously, I was using Mysql JDBC driver 5.1.23 to connect to the DB. Everything worked. I recently upgraded to Mysql JDBC driver 5.1.33. After the upgrade, Tomcat would throw this error when starting the app.

WARNING: Unexpected exception resolving reference java.sql.SQLException: The server timezone value 'UTC' is unrecognized or represents   more than one timezone. You must configure either the server or JDBC driver (via   the serverTimezone configuration property) to use a more specifc timezone value if   you want to utilize timezone support. 

Why is this happening?

like image 566
bluecollarcoder Avatar asked Oct 22 '14 19:10

bluecollarcoder


People also ask

How do I set MySQL timezone to UTC?

Option 2: Edit the MySQL Configuration File Scroll down to the [mysqld] section, and find the default-time-zone = "+00:00" line. Change the +00:00 value to the GMT value for the time zone you want. Save the file and exit. In the example below we set the MySQL Server time zone to +08:00 (GMT +8).

How do I fix no suitable driver found for JDBC MySQL?

In brief, we can say that such an error occurs when no JDBC JAR file is added to the classpath of Java. Just we need to add the JAR file to the classpath and then execute the code. The code will hopefully get executed with success.

How do I change the time zone on my database?

Use the ALTER DATABASE SET TIME_ZONE command to change the time zone of a database. This command takes either a named region such as America/Los_Angeles or an absolute offset from UTC. This example sets the time zone to UTC: ALTER DATABASE SET TIME_ZONE = '+00:00';


2 Answers

Apparently, to get version 5.1.33 of MySQL JDBC driver to work with UTC time zone, one has to specify the serverTimezone explicitly in the connection string.

jdbc:mysql://localhost/db?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC 
like image 146
bluecollarcoder Avatar answered Sep 27 '22 20:09

bluecollarcoder


I've solved this problem by configuring MySQL.

SET GLOBAL time_zone = '+3:00';

like image 28
Dmitriy Rud Avatar answered Sep 27 '22 21:09

Dmitriy Rud