MySQL: Access Denied Error 1045
Problem:
Users encounter the "ERROR 1045 - Access denied for user 'root'@'localhost' (using password: YES)" error when attempting to access MySQL through the command line. Despite uninstalling and reinstalling MySQL, resetting passwords, and following various guides, the issue persists.
Solution:
For users who have forgotten or lost their root password:
-
Stop MySQL: Stop the MySQL service.
-
Start MySQL with Skip-Grant Tables: Manually restart MySQL using the --skip-grant-tables option: mysqld_safe --skip-grant-tables.
-
Connect with Root: Open a new terminal and connect to MySQL as root: mysql -u root.
-
Reset Root Password: Reset the root password using the following MySQL command for MySQL versions prior to 5.7: UPDATE mysql.user SET Password=PASSWORD('password') WHERE User='root'; For MySQL version 5.7 and above: UPDATE mysql.user SET authentication_string=PASSWORD('password') WHERE User='root';.
-
Flush Privileges: Flush the privileges to update the database table: FLUSH PRIVILEGES;.
Additional Tips:
- Ensure that you have deleted all traces of MySQL after uninstalling it to ensure a fresh installation.
- Refer to the provided link for additional details on resetting the root password.
The above is the detailed content of MySQL Error 1045: How to Fix 'Access Denied' for Root User?. For more information, please follow other related articles on the PHP Chinese website!