The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone问题解决

今天在学习Mybatis时使用JDBC连接数据库时出了一些问题:

一、首先是数据库驱动更变旧版的com.mysql.jdbc.Driver已过时不再适用,提示更变为com.mysql.cj.jdbc.Driver,通过SPI自动注册,不再需要手动加载驱动类

Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.

二、处理完上面的出现如下Mysql数据库问题

Sat Apr 14 14:18:21 CST 2018 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.(这个不是主要问题)

之后出现如下问题:

Access denied for user 'root'@'localhost' (using password: YES)

接着处理该内容问题:

以管理员运行cmd.exe ,进入到对应Mysql数据库bin目录下

进入mysql数据库,然后输入use mysql使用该数据库,再修改password

最好退出mysql,重启mysql服务,在命令行中运行"mysql -uroot -padmin",问题解决

三、前面两个都解决后却又出现了这个问题

java.sql.SQLException: 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.

原来是时区问题;我们所在的是东八区:可以设置成"+8:00"来表示东八区;

中间的SYSTEM 是我测试的没用,只要set global time_zone='+8:00';就可以了

在使用MySQL 8.0之前版本的设置上面的就可以了,而在使用MySQL 8.0以上版本(MySQL连接驱动和版本都是8.0以上)的时候又会出现的该问题错误,我们需要在访问数据库的Url后面加上以下的语句即可:例如:

我一开始的url是

jdbc:mysql://localhost:3306/ssm

加上

?serverTimezone=GMT%2B8

改成

jdbc:mysql://localhost:3306/ssm?serverTimezone=GMT%2B8

其中GMT%2B8表示东八区

最后再测试下,终于可以了,没有再报错了。

第一次没经验费了大把精力在找资料,下次再碰到这个问题就有经验了,以防万一,记录下来以作参考

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值