终是木兰弃了剑 2020-10-11 19:18 采纳率: 0%
浏览 911

springboot 配置数据源问题,连接不上数据库?

server.port=8080

spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:8080/db?serverTimezone=Asia/Shanghai&useSSL=false&characterEncoding=utf-8

mybatis.configuration.map-underscore-to-camel-case=true

配置好properties后启动springboot连接不上数据库,报错如下:

Error updating database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.

Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.] with root cause

查了很多也没法解决,用户名密码正确,数据库名称正确,就是连接不上。。

  • 写回答

3条回答 默认 最新

  • nlw 2020-10-12 08:16
    关注

    com.mysql.jdbc.Driver 是 mysql-connector-java 5中的,
    com.mysql.cj.jdbc.Driver 是 mysql-connector-java 6以上的
    试试去掉cj

    评论

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?