com.mysql.jdbc.Driver 是 mysql-connector-java 5中的,
com.mysql.cj.jdbc.Driver 是 mysql-connector-java 6以上的
我使用的新版驱动maven坐标
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.13</version> </dependency>
启动报错: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.
解决方法:
1.首先是更新驱动类名为:com.mysql.cj.jdbc.Driver
2.然后注意屏蔽ssl校验 不推荐不使用服务器身份验证来建立SSL连接。 如果未明确设置,MySQL 5.5.45+, 5.6.26+ and 5.7.6+版本默认要求建立SSL连接。 为了符合当前不使用SSL连接的应用程序,verifyServerCertificate属性设置为’false’。 如果你不需要使用SSL连接,你需要通过设置useSSL=false来显式禁用SSL连接。 如果你需要用SSL连接,就要为服务器证书验证提供信任库,并设置useSSL=true。 SSL – Secure Sockets Layer(安全套接层) serverTimezone=Asia/Shanghai&useUnicode=true&useSSL=false&characterEncoding=utf-8
还得加入时区制定,否则会报错:
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.