MySql :8.0.18
Introduced mysql driver:
SpringBoot integration framework Mybatis, the time of the visit Controller:
ava.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:129) ~[mysql-connector-java-8.0.18.jar:8.0.18]
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97) ~[mysql-connector-java-8.0.18.jar:8.0.18]
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89) ~[mysql-connector-java-8.0.18.jar:8.0.18]
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63) ~[mysql-connector-java-8.0.18.jar:8.0.18]
......
Internet to find solutions to problems found in the database url address in my profile application.yml.
server:
port: 8080
spring:
datasource:
url: jdbc:mysql://localhost:3306/heima29
username: root
password: houchen
hikari:
maximum-pool-size: 20
minimum-idle: 10
mybatis:
type-aliases-package: cn.itcast.userservice.pojo
Queries to the solution as follows :( guess estimate is because jdbc driver SpringBoot 2.1.x version used is more than 6.0 bar)
The reason is because of the use Mysql Connector / J version 6.x or more, and then they reported the wrong time zone
Problems encountered: servertime = UTC resulting in eight hours time difference
MySQL jdbc 6.0 or later must configure this parameter
Solution:
Can not simply be written when configuring the url: jdbc: mysql: // localhost: 3306 / mysql
We must write: jdbc: mysql: // localhost: 3306 / mysql serverTimezone = UTC?
server:
port: 8080
spring:
datasource:
url: jdbc:mysql://localhost:3306/heima29?serverTimezone=?serverTimezone=UTC
username: root
password: houchen
hikari:
maximum-pool-size: 20
minimum-idle: 10
mybatis:
type-aliases-package: cn.itcast.userservice.pojo
While the above plus the area of the program is not wrong, but we have a problem in inserting java code into the database when the time.
For example, in java code inserted inside time: 2017-08-21 17:29:56
But in time it is displayed inside the database: 2017-08-21 09:29:56
Because of time zone issues.
On behalf of UTC is a global standard time, but the time we are using the Beijing time zone is east eight districts, leading UTC eight hours.
UTC + (+0800) = local (Beijing) time
solution:
server:
port: 8080
spring:
datasource:
url: jdbc:mysql://localhost:3306/heima29?serverTimezone=Asia/Shanghai
username: root
password: houchen
hikari:
maximum-pool-size: 20
minimum-idle: 10
mybatis:
type-aliases-package: cn.itcast.userservice.pojo
SpringBoot mysql出现The server time zone value '�й���ʱ��' is unrecogni