java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)
时间: 2023-09-19 13:11:26 浏览: 41
This error message indicates that there is a problem with the MySQL user credentials being used to access the database. The user 'root'@'localhost' is being denied access to the database because the password being used is incorrect or the user does not have the necessary privileges to access the database.
Possible solutions to this error include:
1. Check the password: Double-check the password being used for the 'root' user account to make sure it is correct. Remember that passwords are case-sensitive in MySQL.
2. Check the user privileges: Verify that the 'root' user account has the necessary privileges to access the database. This can be done by logging in to the MySQL server as the root user and running the command "SHOW GRANTS FOR 'root'@'localhost';". This will display the privileges that the user has been granted.
3. Reset the password: If the password is incorrect or has been forgotten, it can be reset using the MySQL command "SET PASSWORD FOR 'root'@'localhost' = PASSWORD('new_password');". This will set a new password for the 'root' user account.
4. Create a new user account: If the 'root' user account does not have the necessary privileges or there is a problem with the account itself, a new user account with the appropriate privileges can be created using the MySQL command "CREATE USER 'new_user'@'localhost' IDENTIFIED BY 'password';". The necessary privileges can then be granted to the new user account using the "GRANT" command.