我嘗試在 spring 專案中連接到 mysql 資料庫并發生錯誤。
create connection error, url: jdbc:mysql://localhost:3306/IwebManager?useUnicode=true&characterEncoding=utf8&allowPublicKeyRetrieval=true, errorCode 1045, state 28000
java.sql.SQLException: Access denied for user 'root '@'localhost' (using password: YES)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:127)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:95)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:862)
at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:444)
at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:230)
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:226)
application.properties 中的配置是
spring.datasource.driverClassName = com.mysql.cj.jdbc.Driver
spring.datasource.url = jdbc:mysql://localhost:3306/IwebManager?useUnicode=true&characterEncoding=utf8&allowPublicKeyRetrieval=true
spring.datasource.username = root
spring.datasource.password = 1234
在 pom.xml 中是
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
<version>8.0.11</version>
</dependency>
我確定密碼是正確的。在cmd中我嘗試了以下命令并且它作業。
mysql -u -root -p
mysql>use IwebManager;
那么可能的原因是什么?謝謝。
uj5u.com熱心網友回復:
=洗掉您的標志兩側的空格application.properties。并且還要確保值后沒有空格(請注意,在您的問題標題中,它正在嘗試以.root 后的空格登錄t)。
您在問題中的復制/粘貼資料之后確實有空格root(在您的真實檔案中可能不知道)
查看帶有所選文本的問題的螢屏截圖(之后的通知root):

轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/447677.html
標籤:爪哇 mysql 弹簧靴 spring-jdbc
下一篇:如何在SpringBoot2.6.4中使用@ConfigurationProperties的記錄(類可能不是最終的)
