mysql连接userSSL

mysql连接版本:

5.1.45

mysql连接url:

jdbc:mysql://localhost:3306/test?useSSL=true&useUnicode=true&characterEncoding=utf8&autoReconnect=true&failOverReadOnly=false
spring:
  datasource:
    url: jdbc:mysql://localhost:3306/test?useSSL=true&useUnicode=true&characterEncoding=utf8&autoReconnect=true&failOverReadOnly=false
    username: root
    password: 123456
    driver-class-name: com.mysql.jdbc.Driver
    hikari:
      connection-test-query: SELECT 1 FROM DUAL
      connection-timeout: 30000
      maximum-pool-size: 20
      max-lifetime: 1800000
      minimum-idle: 5

报错:

Caused by: javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: java.security.cert.CertPathValidatorException: Path does not chain with any of the trust anchors

mysql连接userSSL_第1张图片

问题出在哪里:证书验证错误

解决:

解决方法1 关闭证书验证.useSSL=false

spring:
  datasource:
    url: jdbc:mysql://localhost:3306/test?useSSL=true&useUnicode=false&characterEncoding=utf8&autoReconnect=true&failOverReadOnly=false
    username: root
    password: 123456
    driver-class-name: com.mysql.jdbc.Driver
    hikari:
      connection-test-query: SELECT 1 FROM DUAL
      connection-timeout: 30000
      maximum-pool-size: 20
      max-lifetime: 1800000
      minimum-idle: 5

解决方法2.mysql版本改为高版本


    mysql
    mysql-connector-java
    8.0.16

然后又报错:

mysql连接userSSL_第2张图片

 解决:

配置serverTimeZone
serverTimezone=Asia/Shanghai

完整配置:

server:
  port: 8081
spring:
  datasource:
    url: jdbc:mysql://localhost:3306/test?useSSL=true&useUnicode=true&characterEncoding=utf8&autoReconnect=true&failOverReadOnly=false&serverTimezone=Asia/Shanghai
    username: root
    password: 123456
    driver-class-name: com.mysql.cj.jdbc.Driver
    hikari:
      connection-test-query: SELECT 1 FROM DUAL
      connection-timeout: 30000
      maximum-pool-size: 20
      max-lifetime: 1800000
      minimum-idle: 5

 

你可能感兴趣的:(mysql)