Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying to set useLegacyDatetimeCode to false in MySQL fails

Tags:

mysql

jdbc

When I set useLegacyDatetimeCode=false in my JDBC connection properties, I get this error message:

java.sql.SQLException: The server timezone value 'CET' 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. The timezones that 'CET' maps to are: Europe/Tirane, Europe/Andorra, Europe/Vienna, Europe/Minsk, Europe/Brussels, Europe/Sofia, Europe/Prague, Europe/Copenhagen, Europe/Tallinn, Europe/Berlin, Europe/Gibraltar, Europe/Athens, Europe/Budapest, Europe/Rome, Europe/Riga, Europe/Vaduz, Europe/Vilnius, Europe/Luxembourg, Europe/Malta, Europe/Chisinau, Europe/Tiraspol, Europe/Monaco, Europe/Amsterdam, Europe/Oslo, Europe/Warsaw, Europe/Lisbon, Europe/Kaliningrad, Europe/Madrid, Europe/Stockholm, Europe/Zurich, Europe/Kiev, Europe/Uzhgorod, Europe/Zaporozhye, Europe/Simferopol, Europe/Belgrade, Africa/Algiers, Africa/Tripoli, Africa/Casablanca, Africa/Tunis, Africa/Ceuta.

I understand what the message is telling me, but I'm not sure what to do about it. I don't have any way of knowing what time zone the MySQL server is running in (this is software that my customers install, and the servers are not managed by me).

I need to set this property to false to fix MySQL time zone bugs.

like image 259
Jesse Barnum Avatar asked Jan 05 '15 17:01

Jesse Barnum


People also ask

How do I set MySQL server time zone?

To explicitly specify the system time zone for MySQL Server at startup, set the TZ environment variable before you start mysqld. If you start the server using mysqld_safe, its --timezone option provides another way to set the system time zone. The permissible values for TZ and --timezone are system dependent.

How do I change timezone to UTC in MySQL?

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 set timezone in JDBC?

To set the timezone for a given JDBC connection, navigate to the Advanced tab and select the timezone from the dropdown menu. By default, UTC is selected.

What is JDBC URL for MySQL?

URL for Connection:- The connection URL for the mysql database is jdbc:mysql://localhost:3306/mydb ('mydb' is the name of database).


1 Answers

You need to pass an additional parameter like this:

db=jdbc:mysql://localhost/db?user=me&pass=secret&useLegacyDatetimeCode=false&serverTimezone=Europe/Vienna
like image 60
Ari Maniatis Avatar answered Oct 08 '22 19:10

Ari Maniatis