mybatis或hibernate框架连接数据库报错:java.sql.SQLException: Access denied for user 'Administrator'@'localhost' (using password: YES)

 

报错信息:

java.sql.SQLException: Access denied for user 'Administrator'@'localhost' (using password: YES)

 

严重: create connection SQLException, url: jdbc:mysql://localhost:3306/db2?&useSSL=false&serverTimezone=UTC, errorCode 1045, state 28000
java.sql.SQLException: Access denied for user 'Administrator'@'localhost' (using password: YES)
    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)
    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
    at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
    at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:835)
    at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:455)
    at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:240)
    at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:199)
    at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1644)
    at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1710)
    at com.alibaba.druid.pool.DruidDataSource$CreateConnectionThread.run(DruidDataSource.java:2753)

 

明明密码对的,被拒绝了,找了好久原因,后来发现将db.properties配置文件里的username改为jdbc.username就好了,可能是因为username被系统变量占用了。
当spring容器在进行启动的时候,会读取当前系统某些环境变量的配置,当前系统的用户名使用username来表示的,所以做好的方式是添加前缀,使用jdbc.username.

 

jdbc.username=root
jdbc.password=root
jdbc.url=jdbc:mysql://localhost:3306/db2?&useSSL=false&serverTimezone=UTC
jdbc.driverClassName=com.mysql.cj.jdbc.Driver

 

 

转: https://www.cnblogs.com/tyhA-nobody/p/13166892.html

 

posted @ 2020-12-09 17:29  与f  阅读(703)  评论(0编辑  收藏  举报