Mysql连接驱动8.0版本改动
mysql-connector-java.jar升级到8版本以后,驱动和连接地址的书写发生了一些改动,不然项目启动会进行报错
1、驱动类发生改变
由 com.mysql.jdbc.Driver 改为 com.mysql.cj.jdbc.Driver
以前的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.
2、数据库连接地址发生改动
spring.datasource.url=jdbc:mysql://localhost:3306/glxy
数据库连接地址上必须要指定时区(serverTimezone=GMT%2B8),不然会报如下错误:
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.
另外,在数据库连接地址上要需要额外指定字符编码(characterEncoding=utf8),如果不指定 like查询可能不会生效,明明有数据却无法查出
完整地址写法如下:
spring.datasource.url=jdbc:mysql://localhost:3306/glxy?serverTimezone=GMT%2B8&characterEncoding=utf8&useSSL=false&useUnicode=true