Java.Sql.Sqlexception: Access Denied for User 'Root'@'Localhost' (Using Password: Yes)

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

As you are creating a database from scratch, you could use:

Connection connection = DriverManager.getConnection("jdbc:mysql://localhost/?user=root&password=rootpassword"); 
PreparedStatement ps = connection.prepareStatement("CREATE DATABASE databasename");
int result = ps.executeUpdate();

Here is an identical scenario.

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

This error is not related to Spring Framework or Spring Boot.
The root cause is your MySQL configuration.

TLRD: you need to grant access to the root user from localhost. The same issue was asked and answered many times on StackOverflow already 1, 2, ...

You can try to configure you application like the following in order to fix your problem:

spring.datasource.url=jdbc:mysql://127.0.0.1:3306/employee_management_system

java.sql.SQLException: Access denied for user 'root'@'localhost' - Can't create connection with mysql

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

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

Reference :

  • https://chartio.com/resources/tutorials/how-to-grant-all-privileges-on-a-database-in-mysql/#:~:text=To%20GRANT%20ALL%20privileges%20to,TO%20%27username%27%40%27localhost%27%3B


Related Topics



Leave a reply



Submit