一、MySQL 5.5.6版本
url 中不论加不加serverTimezone属性,返回的时间都会少8小时,相当于后面测试中的第二种情况,默认时区为东八区。
二、MySQL 8.0.20版本
url中必须添加serverTimezone属性,否则进行sql操作时会报如下的错:
java.sql.SQLException: The server time zone value '�й���ʱ��' 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.
服务器时区值’。©���ʱ��’无法识别或代表多个时区。如果要利用时区支持,则必须配置服务器或JDBC驱动程序(通过“ serverTimezone”配置属性)以使用更特定的时区值。
三、 测试(8.0.20版本)
0. 实际数据


本文探讨了MySQL 5.5.6和8.0.20版本关于时区的问题。在5.5.6版本中,无论是否设置`serverTimezone`,返回时间均默认为东八区,少8小时。而在8.0.20版本中,不设置`serverTimezone`会导致错误,需明确指定时区。通过测试发现,设置`serverTimezone=GMT`或`UTC`并结合实体类JsonFormat的不同时区配置,会影响时间的显示,影响时间正负偏差8小时。
最低0.47元/天 解锁文章
1159





