Mybatis的serverTimezone时区出现问题
错误信息
我们可以定位错误信息The server time zone value Öйú±ê׼ʱ¼ä is, 则说明了是serverTimezone时区的问题
org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: 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. ### The error may exist in com/chun/dao/UserMapper.xml ### The error may involve com.chun.dao.UserMapper.getUserList ### The error occurred while executing a query ### Cause: java.sql.SQLException: The server time zone value Öйú±ê׼ʱ¼ä is unrecognized or represents more than one time
出现原因
因为MySQL版本号是8.0以上,需要设置serverTimezone,useSSL等参数
解决
在mybatis-config.xml文件中的property name="url"在后面添加
&serverTimezone=Asia/Shanghai" //注意Shanghai是开头大写 或者 &serverTimezone=GMT%2B8
<property name="url" value="jdbc:mysql://localhost:3306/mybatis?useSSL=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai"/>