MySQL: setting time_zone in my.cnf options file

落爺英雄遲暮 提交于 2019-11-30 17:26:39

it should be

default_time_zone=Brazil/East

details : http://dev.mysql.com/doc/refman/5.5/en/server-system-variables.html#sysvar_time_zone

Option-File Format = default_time_zone

For MAMP, I added default_time_zone=-03:00 under [mysqld] in /Applications/MAMP/conf/my.cnf

I would get the following error for Brazil/East, probably because its deprecated(https://en.wikipedia.org/wiki/List_of_tz_database_time_zones):

[ERROR] Fatal error: Illegal or unknown default time zone 'Brazil/East'

I'm not certain what has changed in Xampp, but this solution only works if you place this line in the proper place. Trust me I tried many times and had to do a pretty thorough search to find this solution.

default-time-zone = "+00:00"

Example:

read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
default-time-zone = "+00:00" <--- Place here.
log_error = "mysql_error.log"

https://community.apachefriends.org/f/viewtopic.php?f=16&t=47656

Also, you'll want to be sure that you have your database populated with the proper time zone names if you are going to use "America/Los_Angeles". I'd recommend using the offset. I'd actually recommend using UTC as your base then converting your time from that point for users based on their timezone which will save you many headaches later and keep your database nice and uniform. Check out the guide I linked below it explained it very clearly for me and I utilized this system. There are many ways to code it but taking this approach will save you a lot of issues.

http://www.vertabelo.com/blog/technical-articles/the-proper-way-to-handle-multiple-time-zones-in-mysql

A bit late, but this might be helpful nonetheless:

When explicitly setting the timezone, confirm that you are using the correct timezone name, keeping in mind the many have been deprecated. You can use https://en.wikipedia.org/wiki/List_of_tz_database_time_zones to confirm.

In my case, using MySQL 5.7, the deprecated timezone name was not working when adding it below the [mysqld] in my mysqld.cnf file. Using the new timezone name, and restarting the mysql service, worked.

So for user @kev here, using America/Sao_Paulo should work, instead of using Brazil/East.

In ~/.my.cnf:

[mysql]
init_command="SET time_zone='Brazil/East'"

Edit the following:

nano /etc/mysql/conf.d/mysql.cnf && systemctl restart mysql ; systemctl status mysql

MySQL.cnf:

[mysql]
default_time_zone=America/Vancouver

See here for current Time Zone formats --> https://en.wikipedia.org/wiki/List_of_tz_database_time_zones

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!