信息发布→ 登录 注册 退出

解决Mybatis的serverTimezone时区出现问题

发布时间:2026-01-11

点击量:
目录
  • Mybatis serverTimezone时区出现问题
    • 错误信息
    • 出现原因
    • 解决
  • Mybatis 插件碰到的时区问题及用法

    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&amp;useUnicode=true&amp;characterEncoding=UTF-8&amp;serverTimezone=Asia/Shanghai"/>

    Mybatis 插件碰到的时区问题及用法

    连接数据库mysql -hlocalhost -uroot -p,回车,输入密码,回车,

    show variables like'%time_zone'; (注意不要漏掉后面的分号),回车

    设置时区 set time_zone = '+8:00';

    以上为个人经验,希望能给大家一个参考,也希望大家多多支持。

    在线客服
    服务热线

    服务热线

    4008888355

    微信咨询
    二维码
    返回顶部
    ×二维码

    截屏,微信识别二维码

    打开微信

    微信号已复制,请打开微信添加咨询详情!