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

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

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

jdbc版本不对
com.mysql.jdbc.Driver 是 mysql-connector-java 5的,
com.mysql.cj.jdbc.Driver 是 mysql-connector-java 6以上的
去掉cj

你的mysql端口是8080吗?