# SpringBoot 连接 低版本 MySql 数据库报错 java.sql.SQLException: Access denied for user ‘root‘@‘localhost‘...
·
SpringBoot 配置 JDBC 连接 低版本 MySql 数据库报错 java.sql.SQLException: Access denied for user ‘root’@‘localhost’ (using password: YES)
段子手168
1、问题描述:
笔者在用 mysql-connector-java-5.1.32.jar 连接 mysql-5.7.22 时,遇到如下错误:

2、分析原因:
在项目的 application.yml 配置文件里,连接 低版本 mysql 时,用户名和密码都需要加上单引号。

3、解决方法:
修改 application.yml 配置文件,用户名和密码都加上单引号。
## D:\java_test\Intesij_idea\spring_cloud_demo\product_service\src\main\resources\application.yml
server:
port: 9001 #端口
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/shop?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai
# url: jdbc:mysql://localhost:3306/shop?useUnicode=true&characterEncoding=utf8
username: 'root'
password: '012311'
application:
name: service-product #服务名称
jpa:
database: MySQL
show-sql: true
open-in-view: true
#spring:
# application:
# name: service-product #服务名称
# datasource:
# driver-class-name: com.mysql.jdbc.Driver
# url: jdbc:mysql://localhost:3306/shop?useUnicode=true&characterEncoding=utf8
# username: root
# password: 012311
# jpa:
# database: MySQL
# show-sql: true
# open-in-view: true

更多推荐


所有评论(0)