Error querying database. Cause: java.sql.SQLException: The server time zone value xxx is unrecognized or represents more XXXXX

created at 11-11-2021 views: 11

Scenario of error: when testing mybatis to connect to Mysql
Specific error message:

F:\Java_Study\Java_JDK\bin\java.exe -ea -Didea.test.cyclic.buffer.size=1048576 "-javaagent:D:\software\IntelliJ IDEA 2021.2.3\lib\idea_rt.jar=4034:D:\software\IntelliJ IDEA 2021.2.3\bin" -Dfile.encoding=UTF-8 -classpath "D:\software\IntelliJ IDEA 2021.2.3\lib\idea_rt.jar;D:\software\IntelliJ IDEA 2021.2.3\plugins\junit\lib\junit5-rt.jar;D:\software\IntelliJ IDEA 2021.2.3\plugins\junit\lib\junit-rt.jar;F:\Java_Study\Java_Code\Mybatis-Study\mybatis-01\target\test-classes;F:\Java_Study\Java_Code\Mybatis-Study\mybatis-01\target\classes;F:\Java_Study\Java_File\apache-maven-3.8.3-bin\apache-maven-3.8.3\maven-repo\mysql\mysql-connector-java\8.0.15\mysql-connector-java-8.0.15.jar;F:\Java_Study\Java_File\apache-maven-3.8.3-bin\apache-maven-3.8.3\maven-repo\com\google\protobuf\protobuf-java\3.6.1\protobuf-java-3.6.1.jar;F:\Java_Study\Java_File\apache-maven-3.8.3-bin\apache-maven-3.8.3\maven-repo\org\mybatis\mybatis\3.2.8\mybatis-3.2.8.jar;F:\Java_Study\Java_File\apache-maven-3.8.3-bin\apache-maven-3.8.3\maven-repo\junit\junit\4.12\junit-4.12.jar;F:\Java_Study\Java_File\apache-maven-3.8.3-bin\apache-maven-3.8.3\maven-repo\org\hamcrest\hamcrest-core\1.3\hamcrest-core-1.3.jar" com.intellij.rt.junit.JUnitStarter -ideVersion5 -junit4 com.kuang.dao.UserDaoTest,test
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.

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/kuang/dao/UserMapper.xml
### The error may involve com.kuang.dao.UserDao.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 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.

reason

The new version of the database linker needs to specify the UTC time zone,

Modify mybatis-config to:

<property name="url" value="jdbc:mysql://localhost:3306/mybatis?useSSL=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT"/>

Originally

<property name="url" value="jdbc:mysql://localhost:3306/mybatis?useSSL=true&useUnicode=true&characterEncoding=UTF-8"/>
<environments default="development">
        <environment id="development">
            <transactionManager type="JDBC"/>
            <dataSource type="POOLED">
                <property name="driver" value="com.mysql.jdbc.Driver"/>
              <!--modify here: jdbc:mysql://localhost:3306-->
                <property name="url" value="jdbc:mysql://localhost:3306/mybatis?useSSL=true&amp;useUnicode=true&amp;characterEncoding=UTF-8&amp;serverTimezone=GMT"/>
                <property name="username" value="root"/>
                <property name="password" value="123456"/>
            </dataSource>
        </environment>
    </environments>
created at:11-11-2021
edited at: 11-11-2021: