在MySQL中,"serverTimezone"参数是否会更改@@ session.time_zone? [英] Does `serverTimezone` param change @@session.time_zone in MySQL?

查看:123
本文介绍了在MySQL中,"serverTimezone"参数是否会更改@@ session.time_zone?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我使用连接URL中的serverTimezone=UTC与MySQL建立连接,这是否会更改与MySQL的连接@@session.time_zone变量?还是通过发布SET time_zone...语句更改@@session.time_zone的唯一方法?我被认为是serverTimezone=UTCuseLegacyDateTimeCode=false的组合会将@@session.time_zone设置为UTC(或我作为serverTimezone的参数传入的任何时区),但是使用MySQL Connector/J测试此行为似乎可以表示没有.

If I'm making a connection to MySQL with serverTimezone=UTC in my connection URL, will that change the @@session.time_zone variable for my connection to MySQL? Or is the only way to alter @@session.time_zone through issuing a SET time_zone... statement? I was lead to believe that the combination of serverTimezone=UTC and useLegacyDateTimeCode=false would set the @@session.time_zone to UTC (or whatever timezone I passed in as an argument to serverTimezone) but testing this behaviour with MySQL Connector/J seems to indicate it does not.

推荐答案

我面临着同样的问题-需要通过配置而是使用JDBC驱动程序.

As I said in a comment, I was facing the same problem -- needed to find a way of doing @@session.time_zone = '+0:00' without a SQL statement, by configuring the JDBC driver instead.

如果您使用属性(Dropwizard甚至是Spring),这是解决方案:

Here's the solution if you're using properties (Dropwizard and maybe Spring):

sessionTimeZone: UTC
useLegacyDatetimeCode: false

或仅将其附加到JDBC连接URL:?sessionTimeZone=UTC&useLegacyDatetimeCode=false

Or just append it to the JDBC connection URL: ?sessionTimeZone=UTC&useLegacyDatetimeCode=false

连接器的文档根本没有提到它(这可能就是为什么有这么多答案指向"serverTimezone"和其他答案的原因.

The connector's documentation doesn't mention it at all (and that's probably why there are so many answers pointing towards 'serverTimezone' and others.

这篇关于在MySQL中,"serverTimezone"参数是否会更改@@ session.time_zone?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆