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
Wrong Answer in Task - Mistake in Algorithm
How to Force a Method to Throw an Exception in Junit Testing
Check If One List Contains Element from the Other
String.Replaceall Single Backslashes With Double Backslashes
Remove Parentheses, Dashes, and Spaces from Phone Number
Crudrepository How to Find by Last Date Between
How to Get a List of All the Implementations of an Interface Programmatically in Java
Cannot Connect to Localhost API from Android App
Chrome Browser Is Not Opening in Selenium Webdriver
How to Modify Log4J Jsonlayout Field Names
How to Send Image With Post Request
Java 8 Streams - How to Merge Elements from the List With the Same Fields to One Element and Sum Up
How to Hide a Request Field in Swagger API
Mockito Not Mocking Private Variables Using @Spy
Calling Method That Exists in Child Classes But Not in Parent Class