场景
在 MySQL 5.5 版本之后,数据库的连接就需要使用 SSL 的安全连接方式,如果 MySQL 没有设置开启 SSL 的话,客户端连接 MySQL 时就会报安全连接错误:
WARN: Establishing SSL connection without server's identity verification is not recommended.
According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set.
For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'.
You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
解决方案
解决的办法是在数据源 datasource 的 url 中添加 useSSL=false
参数:
spring:
datasource:
url: jdbc:mysql://127.0.0.1:3306/demo?useSSL=false