一、错误现象
在SSM项目中使用阿里的德鲁伊数据源连接数据,在访问数据库时,报如下错误
Access denied for user ‘??—?·?’@‘localhost’ (using password: YES)
二、解决
在写数据库配置文件时,如下:
db.properties
url = jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone = GMT
driverClassName = com.mysql.cj.jdbc.Driver
username = root
password = 101010
filters = stat
maxActive = 20
initialSize = 1
maxWait = 60000
minIdle = 10
maxIdle = 15
timeBetweenEvictionRunsMillis = 60000
minEvictableIdleTimeMillis = 300000
validationQuery = SELECT 'x'
testWhileIdle = true
testOnBorrow = false
testOnReturn = false
maxOpenPreparedStatements = 20
removeAbandoned = true
removeAbandonedTimeout = 1800
logAbandoned = true
其中使用了 “username” 作为属性名,导致在连接数据库时,使用的不是这里配置“root”,而是使用了系统管理员的名称,导致数据库连接报错
将属性名 “username” 该为其他名称,成功解决。
db.properties
jdbc.username = root
引用
<property name = "username" value = "${jdbc.username}" />
参考:
https://www.cnblogs.com/xianshen/p/12745821.html