SpringBoot启动报错:HikariPool-1 - Exception during pool initialization.
com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure

原因:jdbc连接失败

解决办法:
1、仔细检查username、password、url中IP地址、端口号等是否正确,特别是IP地址更换环境容易忘记修改。
2、如果你使用的是SpringBoot 2.0以上版本,应配置为driver‐class‐name: com.mysql.cj.jdbc.Driver

参考配置文件application.yml:

spring:
  datasource:
    username: root
    password: 123456
# url: jdbc:mysql://10.21.14.105:3307/JDBC?characterEncoding=utf-8&&useSSL=false&&serverTimezone=UTC
# 1、serverTimezone是配置时间区域
# 2、url 配置规则 jdbc:mysql:// + ip地址 + 端口 / 数据库名字 ? 字符编码 && 是否使用SSL && 时间区域
# 3、useSSL MySQL在高版本需要指明是否进行SSL连接
    url: jdbc:mysql://10.21.14.105:3307/JDBC  # mysql04
    
#    注意SpringBoot版本在2.0以前和2.0以后的配置有一些不同
#    driver-class-name: com.mysql.jdbc.Driver SpringBoot 2.0以前的版本
    driver‐class‐name: com.mysql.cj.jdbc.Driver

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐