【全网最全-03-MySQL】The server time zone value *** is unrecognized or represents more than one time zone

    技术2024-10-07  49

    【全网最全-03-MySQL】The server time zone value *** is unrecognized or represents more than one time zone

    【问题描述】

    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 的 JDBC 驱动从 6.0 版本以上就必须设置 serverTimezone 参数

    博主本人使用的MySQL 8.0.15对应驱动jar包:mysql-connector-java:8.0.15

    【解决】

    ///在db连接串后面加上:?serverTimezone=UTC //示例: "jdbc:mysql://localhost:3306/test?serverTimezone=UTC" //UTC指协调世界时间

    【拓展】

    解决中文乱码问题 //在db连接串后面加上:?useUnicode=true&characterEncoding=UTF-8 //示例: "jdbc:mysql://localhost:3306/dbname?useUnicode=true&characterEncoding=UTF-8" 解决Establishing SSL connection 警告

    【根本原因】 在MySQL 5.5.45+、5.6.26+和5.7.6+的要求中,如果没有设置显式选项,则默认情况下必须建立SSL连接。

    【解决】设置useSSL=false显式禁用SSL,或者设置useSSL=true并为服务器证书验证提供信任存储。

    //在db连接串后面加上:useSSL=false //示例: "jdbc:mysql://localhost:3306/dbname?useSSL=false"
    Processed: 0.010, SQL: 9