Spring Boot 连接 MySQL 数据库
application.properties文件配置:
#配置数据库 spring.datasource.url= jdbc:mysql://127.0.0.1:3306/demo01 spring.datasource.username= root spring.datasource.password= root spring.datasource.driver-class-name= com.mysql.jdbc.Driver
//错误 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.
原因:MySQL连接驱动更新了。
//异常 java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time
原因:未指定时区serverTimezone,GMT%2B6为东八区,即中国时区。
修改后配置为:
#配置数据库 spring.datasource.url= jdbc:mysql://127.0.0.1:3306/demo01?serverTimezone=GMT%2B8 spring.datasource.username= root spring.datasource.password= root spring.datasource.driver-class-name= com.mysql.cj.jdbc.Driver