0

I try to connect to a mysql database in a spring project and error occurred.

 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)

The configuration in application.properties is

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

In pom.xml is

<dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
            <version>8.0.11</version>
</dependency>

I'm sure the password is correct. And in cmd I tried following command and it work.

mysql -u -root -p
mysql>use IwebManager;

So what's the possible reason? Thx.

kk luo
  • 549
  • 1
  • 9
  • 22

1 Answers1

1

Remove the spaces on the sides of the = signs in your application.properties. And also make sure you have no spaces after the values (notice in your question title it's trying to log in as root with a space after the t).

You do have spaces after root in the copy/pasted data in the question (couldn't possibly know in your real file)

Look at a screenshot of your question with the text selected (notice after root):

Copy/paste spaces image

Jcl
  • 27,696
  • 5
  • 61
  • 92
  • Thanks.one more question if u don't mind.I remove the space and this time has error"The server time zone value XXX unrecognized". Do I had to add timezone parameter in URLor can I add an time zone entry in application.properties? – kk luo Mar 23 '22 at 09:01
  • @kkluo sounds like this issue: https://stackoverflow.com/questions/26515700/mysql-jdbc-driver-5-1-33-time-zone-issue . You have multiple possible solutions there – Jcl Mar 23 '22 at 10:37