nacos连接数据库启动报错“InvalidConnectionAttributeException: ==The server time zone value ‘?й???????‘ is ...“

错误日志

第一段报错

org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.

第二段报错

com.mysql.cj.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.
第二段标记部分说明mysql服务的时区不能识别或者定义了多个时区,错误日志后边也给出了两个解决办法

解决

方法1:配置jdbc连接

在nacos的application.properties配置数据库连接的时候,jdbc连接参数添加时区

# 数据库配置
spring.datasource.platform=mysql

db.num=1
# 时区属性serverTimezone=UTC,UTC是世界标准时间
db.url.0=jdbc:mysql://127.0.0.1:3306/nacos_config?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&serverTimezone=UTC
db.user=root
db.password=123456

方法2:配置mysql的默认时区时间

// 查看mysql时区
show variables like '%time_zone'

如图,mysql的时区(time_zone)取系统时间,而系统时间(system_time_zone)为空
未修改的mysql时区
在MySQL安装目录的my.ini文件的[mysqld]下配置时区default-time-zone=’+08:00’,配置完成后重启mysql

[mysql]
default-character-set=utf8 
[mysqld]
port = 3306 
basedir=D:\programFile\MySQLServer5.7
# 设置时区
default-time-zone='+08:00'

在这里插入图片描述
关于这两个变量的作用可以参考: time_zone变量解释

  • 8
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值