错误日志
第一段报错
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安装目录的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变量解释