Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cant set mysql timezone to madrid

According to this question on how to set the time_zone in mysql and this timezone list, I thougth this should work:

SET time_zone = 'Europe/Madrid';

But this is what sqlBuddy logs:

The following errors were reported:Unknown or incorrect time zone: 'Europe/Madrid'

like image 1000
Toni Michel Caubet Avatar asked Jul 04 '12 15:07

Toni Michel Caubet


People also ask

How do I set MySQL timezone?

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 change my timezone in my CNF?

You can also set MySQL server time zone in your server configuration file my. cnf. Open the file in a terminal. Change the '+00:00' to your time zone's GMT offset, such as '-6:00'.

What timezone is now () MySQL?

The MySQL NOW() function returns the current date and time in the configured time zone as a string or a number in the 'YYYY-MM-DD HH:MM:DD' or 'YYYYMMDDHHMMSS.

How do I set MySQL timezone to Asia Calcutta?

date_default_timezone_set('Asia/Calcutta'); Show activity on this post. You can simply use the "date_default_timezone_set" function to set the date to your location.


2 Answers

Ensure that the time zone information tables have been populated. From mysql:

The value can be given as a named time zone, such as 'Europe/Helsinki', 'US/Eastern', or 'MET'. Named time zones can be used only if the time zone information tables in the mysql database have been created and populated.

Although personally I prefer storing all dates in UTC. I find it makes reasoning far simpler particularly when daylight savings time is introduced.

like image 80
Rich O'Kelly Avatar answered Oct 13 '22 00:10

Rich O'Kelly


An alternate solution if you don't want to make your own timezone settings tables.

If have your own server, leave MySQL as it is. It defaults to the timezone SYSTEM.

Ubuntu users can use

dpkg-reconfigure tzdata

For more conservative OSes (Centos, RedHat, Fedora) use

tzconfig

commands for changing the system timezone. A CLI application will pop up where you can select the region and location. It's not only two birds by one stone, but it also automatically accomodates to daylight changes without having to specify when and what in MySQL timezone tables.

enter image description here

Don't forget to restart your MySQL server for the changes to take effect.

like image 45
Rápli András Avatar answered Oct 13 '22 01:10

Rápli András