1

springboot version 4.3.10
mysql version 5.7.18
java version 1.8 mysql-connector-java version 5.1.38

ERROR 5976 --- [ main] o.a.tomcat.jdbc.pool.ConnectionPool:Unable to create initial connections of pool. java.sql.SQLException: Access denied for user 'root '@'localhost' (using password: NO)

Neil Stockton
  • 11,383
  • 3
  • 34
  • 29
user8393526
  • 13
  • 1
  • 1
  • 4
  • 1
    The error message is "Access denied for user 'root '@'localhost' ". Check to see that the password is correct. – krismath Jul 31 '17 at 11:15
  • The problem is if you have password than you are not providing that while connecting to database thats why it shows (using password: NO). So, use that password while connecting. So, the problem is wrong connection parameters for sure. – Jaydatt Jul 31 '17 at 11:21
  • Did you try resetting password or inserting root user forcefully? – sForSujit Jul 31 '17 at 11:39
  • the password is right,i cat use the pasword login on the DOS. – user8393526 Jul 31 '17 at 12:16
  • Refer to this solution https://stackoverflow.com/questions/52174740/java-sql-sqlexception-access-denied-for-user-localhost-using-password-no/54758181#54758181 – briancollins081 Feb 19 '19 at 03:07

4 Answers4

0

Please check the configurations and database properties ( valid credentials username and password) in application.properties

https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html

Follow the link :

https://www.mkyong.com/spring-boot/spring-boot-jdbc-mysql-hikaricp-example/

Lakshman Miani
  • 344
  • 1
  • 5
  • 20
0

'root '@'localhost' (using password: NO)

Maybe try to configure your password to your mysql configs

  • i found the answer,the configeration file application.properties is wrong,when i was using application.yml,the mistake is gone. – user8393526 Jul 31 '17 at 12:58
0

Sample mysql mapping in application.properties

schemaname -> your mysql schema name you are trying to connect

passwordforschema -> your schema password

spring:
    datasource:
        driver-class-name: com.mysql.jdbc.jdbc2.optional.MysqlDataSource
        url: jdbc:mysql://localhost:3306/schemaname
        username: root
        password: passwordforschema
Yusuf Kapasi
  • 577
  • 2
  • 9
  • here is the configeration #DB spring.datasource.url = jdbc:mysql://localhost:3306/blog?useUnicode=true&useSSL=true spring.datasource.driverClassName = com.mysql.jdbc.Driver spring.datasource.username = root spring.datasource.password = – user8393526 Jul 31 '17 at 12:11
  • I hope you have tried connecting to database using the same user name and password you are using in the spring boot and also that user has sufficient privileges. – Yusuf Kapasi Jul 31 '17 at 12:17
  • com.mysql.jdbc.jdbc2.optional.MysqlDataSource cannot be cast to java.sql.Driver – user8393526 Jul 31 '17 at 12:19
  • yes i tried,but i don't know how to check the privileges – user8393526 Jul 31 '17 at 12:24
  • This is the privileges GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION – user8393526 Jul 31 '17 at 12:27
  • In your database configuration java file check whether you are using configuration.setDriverClassName() or configuration.setDataSourceClassName(), the later is the correct way. – Yusuf Kapasi Jul 31 '17 at 12:28
  • thanks for you answer,i fixed the problem,at the first i use the application.properties,no matter how to config is just not right,but when i was using the application.yml,the mistake is gone. forgive my poor english – user8393526 Jul 31 '17 at 12:56
  • @user8393526 That's great. can you accept the answer if this helped. – Yusuf Kapasi Aug 01 '17 at 04:48
0

I think your problem is password-error. If you cannot resolve the question, try to check the things below. Or you can try to connect your mysql server by IDE first.

  1. make sure you open mysql service, you can test connect it with IDE database function, like IDEA.
  2. take care of useSSL=false, sometimes it will be fatal.
  3. If your mysql-connector-java's version is above 8.*, that you might need to change the datasource-driver-name to com.mysql.cj.jdbc.Driver

Though spring will help you change.

  1. If you specify jpa with table's names, columns. Make sure you use the right grammar @Table(name='xxx') @Column(name= 'xxx')
  2. Take care of the mysql server's port.

In windows. netstat -ano |findstr: 3306

taskkill /PID enterPID /F

In Linux netstat -anp |grep 3306 kill -9 pid

  • Check gradle or maven dependencies
  • And here is where I get stuck.

In spring-boot, you can make the configuration set up automatically. But you need to make the files right in their places.

  • xx.yml need put in resources(In IDEA, you need to specify the package as resources package)
  • xxxApplication.class(The spring-boot-starter class should be out of other classes, or you should specify the other classes' path.
Community
  • 1
  • 1
tyrantqiao
  • 319
  • 4
  • 7