The server time zone value 'CEST' is unrecognized - mysql

I am using hibernate (Hibernate Maven 5.2.15.Final, Mysql-connector Maven 8.0.9-rc) whith mysql 5.7 on lampp environment on linux so.
I am in Italy (Central European Summer Time) and once March 25, occurs follow error on connection db:
The server time zone value 'CEST' 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.
On mysql console, I ran:
SHOW GLOBAL VARIABLES LIKE 'time_zone';
SET GLOBAL time_zone='Europe/Rome';
but that did not persist.
Then I added to my.cnf file (in /etc/mysql):
[mysqld]
default-time-zone = 'Europe/Rome'
and also:
default_time_zone = 'Europe/Rome'
but the db server did not start still...
Why does the error occur?
Could someone help me?
Thank you!

#aiman's answer is not correct since in your case the effective server timezone is not UTC.
You'll find on the net some solutions including additional parameters on the jdbc connection string, but there are cases where you cannot change this string.
Here's how I fixed it:
First import the system timezones in mysql:
$ mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql
Then set your default mysql server timezone in the [mysqld] section of /etc/mysql/my.cnf (or of /etc/mysql/mysql.conf.d/mysqld.cnf on recent Debian/Ubuntu distros) to your actual server timezone, for instance:
default_time_zone = Europe/Paris
and don't forget to restart mysql
$ sudo service mysql restart
(or the appropriate command depending on your distro).

If the problem is when connecting to the db, I found the solution in the NOTE of this answer.
In your connection url use the following:
String url = "jdbc:mysql://localhost/mydb?serverTimezone=Europe/Rome";
This worked for me to connect with flyway and timezone Europe/Amsterdam.

First see your mysql server timezone:
mysql -e "SELECT ##global.time_zone;" -u <mysqluser> -p.
Most probably it should be SYSTEM.
Find your system timezone: date +”%Z.
See if its CEST.
You need to change your system timezone:
#cd /usr/share/zoneinfo
#ls -l
#rm /etc/localtime
#ln -s /usr/share/zoneinfo/UTC /etc/localtime
Then restart your mysql server: /etc/init.d/mysqld restart.
Enjoy

This cropped up out of the blue on my dev machine - restarting MySQL fixed for me

Related

Trying to setup keycloak with mySQL but fails due to timezone issue

So, we're trying to setup keycloak using the quay.io docker image and connecting it with our mySQL database. While startup, we see this error:
Caused by: java.sql.SQLException:
The server time zone value 'CDT' 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 specific time zone value if you want to utilize time zone support.
We can't reset our mysql or mysql host instance timezone - is there any other way we can override the serverTimezone parameter?
Yes, you can set timezone. If quay.io based on debian. You can try something similar to
ENV TZ=Asia/Colombo
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
Please change timezone to same as your MySQL instance.
To build Quay image, please follow official guide
FROM quay.io/keycloak/keycloak:latest
USER root
ENV TZ=UTC
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
You no need to sudo as you use root user

How to change timezone in my.cnf keeping daylight savings in consideration

How do we set timezone in my.cnf in mysql?
I tried to set UK's timezone to my mysql server like this:
[mysqld]
default-time-zone= "Europe/London"
I can't even restart mysql when I add this line so this seems to be wrong for some reason. I tried to set it using mysql client and I am getting this error.
if I set it to GMT, would it work fine in the case of daylight savings?
Took me ages to find this as I thought timezone tables would be default populated - so hopefully this helps someone else
You can do it using the line you have Danyal BUT you have to load the timezone info into mysql first
So on the server run this as root
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql
Then in my.cnf use
[mysqld]
default-time-zone = 'Europe/London'

Database returned an invalid value in QuerySet.dates()

I get this error on my Ubuntu 12.04 machine with mysql 5.5 after I imported some Wordpress content to Mezzanine's blog_blogpost.
ValueError at /admin/blog/blogpost/
Database returned an invalid value in QuerySet.dates(). Are time zone definitions and pytz installed?
Request Method: GET
Request URL: http://127.0.0.1:8000/admin/blog/blogpost/
Django Version: 1.6.1
Exception Type: ValueError
Exception Value:
Database returned an invalid value in QuerySet.dates(). Are time zone definitions and pytz installed?
Exception Location: /home/me/.mezenv/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py in results_iter, line 1107
Python Executable: /home/me/.mezenv/bin/python
Python Version: 2.7.3
Python Path:
[u'/home/me',
'/home/me/sai',
'/home/me/.mezenv/local/lib/python2.7/site-packages/distribute-0.6.24-py2.7.egg',
'/home/me/.mezenv/local/lib/python2.7/site-packages/pip-1.1-py2.7.egg',
'/home/me/.mezenv/lib/python2.7',
'/home/me/.mezenv/lib/python2.7/plat-linux2',
'/home/me/.mezenv/lib/python2.7/lib-tk',
'/home/me/.mezenv/lib/python2.7/lib-old',
'/home/me/.mezenv/lib/python2.7/lib-dynload',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-linux2',
'/usr/lib/python2.7/lib-tk',
'/home/me/.mezenv/local/lib/python2.7/site-packages']
Server time: Sat, 25 Jan 2014 13:44:11 +0100
Error during template rendering
In template /home/me/.mezenv/local/lib/python2.7/site-packages/grappelli_safe/templates/admin/change_list.html, error at line 140
I added to my local_settings.py
import pytz
from pytz import *
and also defined timezone in my.cnf [mysqld]
default-time-zone = "+01:00"
but I still get the error unitl I get the line in template:
the tag is:
140 {% block date_hierarchy %}{% date_hierarchy cl %}{% endblock %}
Appreciate your help to resolve it.
Looks like error caused Django's 1.6 timezone functionality changes. The docs now mention this error specifically (bug report, link to docs).
You have to load timezone tables into mysql (http://dev.mysql.com/doc/refman/5.6/en/mysql-tzinfo-to-sql.html).
Try execute on your database server:
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -D mysql -u root -p
And then run "flush tables" or "flush query cache", otherwise the problem may not disappear even though you've loaded the correct timezone data:
mysql -u root -p -e "flush tables;" mysql
updated by #qris
What worked for me:
1. Populate the timezone definitions in the 'mysql' table
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql
2. Flush tables
mysql -u root -p -e "flush tables;" mysql
3. Restart mysql
sudo service mysql restart
For MacOS users I found solution here (in comment):
mysql_tzinfo_to_sql /usr/share/zoneinfo | sed -e "s/Local time zone must be set--see zic manual page/local/" | mysql -u root mysql
Because on MacOS we have error looks like this:
$ mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u roomysql
Warning: Unable to load '/usr/share/zoneinfo/+VERSION' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/Asia/Riyadh87' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/Asia/Riyadh88' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/Asia/Riyadh89' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/Mideast/Riyadh87' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/Mideast/Riyadh88' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/Mideast/Riyadh89' as time zone. Skipping it.
ERROR 1406 (22001) at line 38981: Data too long for column 'Abbreviation' at row 1
For Windows, take the following steps:
stop the service
download the files provided by MySQL but note they go in C:\ProgramData\MySQL\MySQL Server VERSION\data\mysql not in C:\Program Files\MySQL\MySQL Server VERSION\data at least on Windows 7 as of 2014.
I also modified C:\Program Files\MySQL\MySQL Server VERSION\my.ini to add default-time-zone = 'UTC' per the tips here. Then restart the service.
For anyone else passing through here with the same issue on Mavericks I was getting the error mentioned by Anton whereby I kept getting;
ERROR 1406 (22001) at line 38981: Data too long for column 'Abbreviation' at row 1
So I used mysql_tzinfo_to_sql tz_file tz_name from the MySQL docs to load the specific time zones that I wanted;
mysql_tzinfo_to_sql /usr/share/zoneinfo/GMT GMT | mysql -u root -p mysql
mysql_tzinfo_to_sql /usr/share/zoneinfo/UTC UTC | mysql -u root -p mysql
And now Django isn't returning errors so I'm happy :D
The Django docs actually talk about this problem:
I get an error “Are time zone definitions for your database and pytz installed?” pytz is installed, so I guess the problem is my database?
If you are using MySQL, see the Time zone definitions section of the MySQL notes for instructions on loading time zone definitions.
If you follow that link, you get this advice:
If you plan on using Django’s timezone support, use mysql_tzinfo_to_sql to load time zone tables into the MySQL database. This needs to be done just once for your MySQL server, not per database.
Here's the command:
mysql_tzinfo_to_sql /usr/share/zoneinfo/ | mysql mysql
Loading Time Zone for Mysql solved the problem for me.
If you are on windows, follow these instructions :
Step #1: Download the package that contains the data files of pre-built time zone tables.
http://dev.mysql.com/downloads/timezones.html
Step #2: Unzip the downloaded ZIP file to a folder on your Desktop.
Step #3: Stop MySQL Server.
For Xampp and Wamp use their GUI or stop the mysql service from the Task Manager.
Step #4: Open mysql subdirectory of your MySQL server's data directory.
For me it is C:\xampp\mysql\data\mysql
Step #5: Overwrite time zone data files with the downloaded version.
Copy all 15 data files from your unzipped folder and paste into data folder for the mysql system database. Overwrite all these .frm, .MYD, and .MYI files.
Step #6: Restart MySQL server.
And the job is done :-)
source : http://www.geeksengine.com/article/populate-time-zone-data-for-mysql.html

Mysql: modification in my.cnf doesn't take effect

I've updated the my.cnf file of my database with the following line: max_connections=200. I stopped and started the mysql service after that so that the changes would take effect.
But for some reason this change doesn't affect the database because if I run:
mysql> select ##max_connections
it shows that the max number of connections is 100.
Obviously there is some place else that manages this value. Where can I find it or what did I do wrong?
Thank you for your reply.
Make sure the max_connections in under the [mysqld] section:
Ex:
[mysqld]
socket=/path/to/mysql.sock
datadir=/var/lib/mysql
max_connections=200
[client]
#mysql-client settings here..
Try running mysqld --verbose --help to see which configuration file is actually read by mysqld and which parameters and values are used.
The output will look like this:
mysqld Ver 5.0.51a-24-log for debian-linux-gnu on x86_64 ((Debian))
Copyright (C) 2000 MySQL AB, by Monty and others
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL license
Default options are read from the following files in the given order:
/etc/mysql/my.cnf ~/.my.cnf /usr/etc/my.cnf
The following groups are read: mysql_cluster mysqld server mysqld-5.0
Variables (--variable-name=value)
and boolean options {FALSE|TRUE} Value (after reading options)
--------------------------------- -----------------------------
...
To see what values a running MySQL server is using, type
'mysqladmin variables' instead of 'mysqld --verbose --help'.
Changes to mysqld are not necessarily reflected in the mysql client! I changed a global variable assignment in my.cnf, restarted the service, and queried it in the mysql client. It returned the old value. When queried from a script, however, the value was in fact changed!
It may have to do with 'how' the mysql server is being shutdown and restarted. On my system if I use the mysqld daemon service to shutdown mysql (e.g. service mysqld stop), I get a shutdown notice, but a ps shows mysql is still running. Using a similar 'service mysqld restart', some of the changes to the my.cnf file get accepted, but many don't.
The other method of shutting down mysql is to use mysqladmin -u user -pPass shutdown. I noticed when I used this method, mysql was shutdown completely (no left overs in ps), and when I restarted the mysql server, all the changes to the my.cnf file were accepted.
If mysql starts as a Window service, check the 'Path to executable' setting on the windows service. (Services -> MYSQL56 -> Properties).
If the --defaults-file option is passed in, it could point to a completely different .ini file in a location that is NOT showing with 'mysqld --verbose --help'.
If you remove the --defaults-file option from the service startup parameters, it will go through the list of ini files as listed with mysqld --verbose --help.
Putting my.cnf in /etc/my.cnf and restarting mysql has resolved the issue for me. I'm using mac os. Mysql version is 5.6.41

Changing the connection timezone in MySQL

My server is running in MDT
So I used following one to convert EST
SET time_zone = '-5:00'
But, how can I switch it to EDT because
While `EST` is only valid in winter, while in summer how to change it to `EDT`
I just try to used named time zone. But I am getting following error
#1298 - Unknown or incorrect time zone: 'America/Toronto'
I don't understand how to solve this problem
How can i switch
UTC -05 TO UTC-04
For Linux, BSD, and Mac OS X if you need to load the timezone table do this:
$ mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -uroot mysql
Since you're using Windows, your going to have to import the time zone description tables to your MySQL server.
http://dev.mysql.com/downloads/timezones.html
For me on Windows using WampServer:
download the POSIX version from https://dev.mysql.com/downloads/timezones.html
unzip it
put all files in wamp mysql data: C:\wamp\bin\mysql\mysql5.7.11\data\mysql
restart wamp
More Info:
“To use a time zone package that contains .frm, .MYD, and .MYI files for the MyISAM time zone tables, download and unpack it. These table files are part of the mysql database, so you should place the files in the mysqlsubdirectory of your MySQL server's data directory. Stop the server before doing this and restart it afterward”
http://dev.mysql.com/doc/refman/5.7/en/time-zone-support.html#time-zone-installation
In case of Mysql8 and want to set EDT timezone 'America/New_York' then follow the below steps:
Go to the /etc/my.cnf
Add this under [mysqld]
default-time-zone='America/New_York'
systemctl restart mysqld
If you face the issue realted fatal error like this:
Fatal error: Illegal or unknown default time zone
Then do the following steps:
first remove the entry from /etc/my.cnf file for default-time-zone='America/New_York'
Go to shell(exit from mysql) and run the command
$ mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql
Add the line again
Restart mysql
Have you tried using a zoneinfo name such as "America/New_York" instead of the abbreviation (which is only valid for half the time)?
Ideally, you shouldn't use the server time zone at all of course - store dates in UTC and then convert it to the appropriate time zone in the client code. (This does depend on what you're storing, mind you. Future date/time values specified by a user with a time zone should be stored that way, not converted to any other time zone, in case the rules change between now and the future date/time. But for instants in time recorded by machines, e.g. for logging, transactions etc, I'd definitely store UTC. I would never suggest storing "just the local time and assume that the server and the client have the same rules".)
Just for the sake of completeness, Mac users can find mysql_tzinfo_to_sql utility in /usr/local/mysql/bin directory.
Hence the complete command will be /usr/local/mysql/bin/mysql_tzinfo_to_sql /usr/share/zoneinfo | ./mysql -p -u root mysql
I spent hours to find the utility, the above path may save yours!