解决jdbc连接mysql报时区错误

    xiaoxiao2025-07-20  10

    连接mysql的时候报了这个错误:

    java.sql.SQLException: The server time zone value '�й���׼ʱ��' is unrecognized or represents more than one time zone

    这是mysql的时区和本地不一致

    可以这样子解决,在连接url后面添加时区参数serverTimezone

    spring: datasource: username: root password: 123456 url: jdbc:mysql://127.0.0.1:3306/infers?serverTimezone=UTC driver-class-name: com.mysql.jdbc.Driver

    时区问题也简单说一下

    UTC是:Coordinated Universal Time 协调世界时间

    GMT:Greenwich Mean Time,格林威治时间 这个是旧的时间,是以前用的标准,后面UTC替代了,和UTC是差不多一样的

    北京时间:CST(china standard time ?)UTC +8 或者GMT +8

    太平洋时间:(美国时间?)PST    = UTC -8  或者 GMT -8 

    添加参数的url连接后,连接成功

    2019-05-26 22:24:15.894 INFO 10336 --- [ main] a.s.SpringBoot06DataJdbcApplicationTests : Starting SpringBoot06DataJdbcApplicationTests on DESKTOP-6MV6QB2 with PID 10336 (started by Administrator in D:\spring-boot-06-data-jdbc) 2019-05-26 22:24:15.895 INFO 10336 --- [ main] a.s.SpringBoot06DataJdbcApplicationTests : No active profile set, falling back to default profiles: default 2019-05-26 22:24:17.030 INFO 10336 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor' 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. 2019-05-26 22:24:17.329 INFO 10336 --- [ main] a.s.SpringBoot06DataJdbcApplicationTests : Started SpringBoot06DataJdbcApplicationTests in 1.705 seconds (JVM running for 2.256) class com.zaxxer.hikari.HikariDataSource 2019-05-26 22:24:17.480 INFO 10336 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting... 2019-05-26 22:24:17.483 WARN 10336 --- [ main] com.zaxxer.hikari.util.DriverDataSource : Registered driver with driverClassName=com.mysql.jdbc.Driver was not found, trying direct instantiation. 2019-05-26 22:24:17.855 INFO 10336 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed. HikariProxyConnection@746228466 wrapping com.mysql.cj.jdbc.ConnectionImpl@10c07b8d 2019-05-26 22:24:17.862 INFO 10336 --- [ Thread-2] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated... 2019-05-26 22:24:17.864 INFO 10336 --- [ Thread-2] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed. 2019-05-26 22:24:17.864 INFO 10336 --- [ Thread-2] o.s.s.concurrent.ThreadPoolTaskExecutor : Shutting down ExecutorService 'applicationTaskExecutor'

     

     

     

    最新回复(0)