–报错信息如下–
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.
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:127)
······
造成这个的原因是maven导入MyBatis的时候会自动导入最新版本的8.0.11,然后8.0.11采用了新驱动,之前版本会报错。当我们使用高版本的MySQL驱动时可以在获取数据库的连接getConnection()的url后面加上serverTimezone=GMT%2B8即可解决问题。例如:jdbc:mysql:///student?&serverTimezone=GMT%2B8。使用低版本的MySQL jdbc驱动5.1.28不会存在时区的问题。
–解决方法–
在你的MySQL安装目录下去找MySQL配置文件my.ini文件,我的是在C:\ProgramData\MySQL\MySQL Server 8.0。找到后右键-打开方式-写字板,然后搜索[mysqld],在[mysqld]下面添加指令然后保存退出:
default-time-zone='+08:00'
重启MySQL的服务后,win+R打开cmd窗口登录MySQL执行show variables like ‘%time_zone%’;这句命令
注: 此文章只为记录开发过程中的错误,学习,如发现侵权请私信删除