欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Could not create connection to database server. Attempted reconnect 3 times. Giving up.

程序员文章站 2022-05-01 15:55:20
...

在启动服务时,报出Could not create connection to database server. Attempted reconnect 3 times. Giving up.这个错误。报错图:

Could not create connection to database server. Attempted reconnect 3 times. Giving up.

这是我的 application.yml 配置信息:


spring:
  application:
    name: softactivity
  http:
    encoding.charset: UTF-8
    encoding.force: true
  mvc:
    static-path-pattern: /**

  resources:
    static-locations: classpath:/templates/
  datasource:
    driver-class-name: com.mysql.jdbc.Driver
    url:  jdbc:mysql://127.0.0.1:3306/works?useUnicode=true&characterEncoding=utf8&autoReconnect=true&rewriteBatchedStatements=true&&allowMultiQueries=true&verifyServerCertificate=false
    username: root
    password: root
    
  jpa:
    database: MYSQL
    show-sql: true

查看多次,上网查询修改了多次,都还是报这个错误。
最终发现因 mysql-connector-java 中的jar版本太高,与自己的mysql版本不符,在这里插入代码片所导致的错误,将jar的版本调到6.0以下即可。本人最终将jar的版本换成了5.1.30,配置信息没有问题,错误解决。Could not create connection to database server. Attempted reconnect 3 times. Giving up.
Could not create connection to database server. Attempted reconnect 3 times. Giving up.

如果还未解决您的问题,请检查配置的正确性或其他:

  datasource:
    driver:xxxx
    url:  xxxx
    username: xxxx
    password: xxxx