1.未指定serverTimezone
xml内里设置url
<property name="url" value="jdbc:mysql://localhost:3306/mybatisstudy"/>
涌现的非常
Caused by: com.mysql.cj.core.exceptions.InvalidConnectionAttributeException: 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 specifc time zone value if you want to utilize time zone support.
您必需设置服务器或JDBC驱动顺序(经由过程serverTimezone设置属性),假如您想要运用时区支撑,则需要运用一个更细致的时区值。
2.网上的解决方案
在url背面加上参数?serverTimezone=utc
<property name="url" value="jdbc:mysql://localhost:3306/springdatastudy?serverTimezone=UTC"/>
2.1.碰到的题目
虽然上面加上时区顺序不出错了,然则我们在用java代码插进去到数据库时候的时刻却涌现了题目。
比如在java代码内里插进去的时候为:2017-08-21 17:29:56
然则在数据库内里显现的时候却为:2017-08-21 09:29:56
3.根本原因
由于时区设置的题目。
UTC代表的是环球标准时候 ,然则我们运用的时候是北京时区也就是东八区,抢先UTC八个小时。
UTC + (+0800) = 当地(北京)时候
4.解决方案
url的时区运用中国标准时候。也是就serverTimezone=Asia/Shanghai
4.1 运用java代码猎取当地的时区id
Calendar cal = Calendar.getInstance(); TimeZone timeZone = cal.getTimeZone(); System.out.println(timeZone.getID()); System.out.println(timeZone.getDisplayName());
Asia/Shanghai 中国标准时候
相干引荐:
MySQL中or语句用法示例
MySQL中关于索引与触发器详解
MySQL中关于日期函数汇总
以上就是详解mysql中url时区的圈套该怎样躲避的细致内容,更多请关注ki4网别的相干文章!