0

I created a Spring Boot project and I want to connect with a database.

This is a .property file

spring.jpa.open-in-view=true
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://${MYSQL_HOST:localhost}:3306/tracking
spring.datasource.username=root
spring.datasource.password=
server.port=8084
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true

In MySQL username=root which doesn't have a password.

mysql port=3306

I get the following error when running the project.

java.sql.SQLException: Access denied for user 'root'@'localhost'
    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129) ~[mysql-connector-java-8.0.22.jar:8.0.22]
SQLError.java:129
    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97) ~[mysql-connector-java-8.0.22.jar:8.0.22]
SQLError.java:97
    at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) ~[mysql-connector-java-8.0.22.jar:8.0.22]
SQLExceptionsMapping.java:122
    at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:836) ~[mysql-connector-java-8.0.22.jar:8.0.22]

How do I solve this error?

I'm working with the Ubuntu operating system.

Also, I use mysql -u root command in the terminal to connect mysql it gives same error. hence I used sudo mysql -u root I can sucessfully use mysql shell

Kaumadie Kariyawasam
  • 1,232
  • 3
  • 17
  • 35
  • change your password and put that in config, https://stackoverflow.com/questions/7534056/mysql-root-password-change – Emerson Micu Apr 19 '21 at 09:42
  • set up a user account with a password, off course there is a password for root user, https://phoenixnap.com/kb/how-to-reset-mysql-root-password-windows-linux – Tiago Medici Apr 19 '21 at 09:44
  • 1
    as others have written - set up a password. But besides this, just now your not trying to login without a password but with an empty string. – juwil Apr 19 '21 at 09:51

2 Answers2

1

Change

spring.datasource.password=''

to

spring.datasource.password=
Simon Martinelli
  • 34,053
  • 5
  • 48
  • 82
0

Maybe is the privileges' problem. Try below command at the MySQL server side.

->GRANT ALL PRIVILEGES ON tracking.* TO 'root'@'localhost';
->FLUSH PRIVILEGES;

Reference :

lee yiyang
  • 75
  • 6