报错:The server time zone value ‘�й���׼ʱ��‘ is unrecognied

报错:The server time zone value ‘�й���׼ʱ��’ is unrecognied

当我们通过JDBC连接数据库的时候有时候会报出以下的错误:

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”配置属性)以使用更具体的时区值。

这是由于使用的JDBC驱动包版本高于6(包括6),当我们使用这些版本连接要使用的URL时,必须加上serverTimezone参数,来设置时区。

解决方法1

将JDBC连接的URL修改为:

jdbc:mysql://localhost:3306/数据库名?serverTimezone=UTC

这里UTC代表全球标准时间,可以根据需要更改其值。

我们使用的时间是北京时间,即东八区时间,领先UTC八个小时。

所以我们可以将URL修改为:

jdbc:mysql://127.0.0.1:3306/test?serverTimezone=GMT%2b8
//上海时区也为东八区
jdbc:mysql://localhost:3306/数据库名?serverTimezone=Asia/Shanghai

解决方法2

当然我们可以直接通过更改使用的驱动包版本来解决该问题,只要使用6以下的版本就能解决。

猜你喜欢

转载自blog.csdn.net/weixin_48177336/article/details/129437724
今日推荐