MySql时区问题的解决方法 The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more t

1、问题

采用代码插入数据早8小时(比如现在时间是21:10:25,那么插入数据库中的数据时13:10:25)

者从数据库中取出数据时迟8小时(比如数据库中的时间是07:30,那么查询出来在页面显示的时间为15:30)

这都是因为安装mysql的时候时区设置的不正确
mysql默认的是美国的时区,而我们中国大陆要比他们迟8小时,采用+8:00格式

2、解决方法,若是win10请右击-属性给予权限后再行操作!

修改my.ini文件(若是安装在C盘的话,目录则是:C:\ProgramData\MySQL\MySQL Server 5.7)

default-time-zone='+08:00'

Paste_Image.png

注意:若是在ubuntu环境下,直接在my.cnf文件中添加该行代码即可,如下图:

mysql修改地方

3、重启mysql,检查mysql时区

show variables like '%time_zone%'; 

Paste_Image.png

现在你插入数据和查询数据都是ok的了,链接数据库也不用写下面的一长串了!

db.url=jdbc:mysql://localhost:3306/sbt_data?serverTimezone=UTC&characterEncoding=utf8&useUnicode=true&useSSL=false

直接这样:

db.url=jdbc:mysql://localhost:3306/sbt_data



转自:https://www.jianshu.com/p/5f792b997d2a

猜你喜欢

转载自blog.csdn.net/qq_38318622/article/details/81110803
今日推荐