MySQL - ERROR 1045: Access Denied - Troubleshooting and Resetting Root Password
Problem:
When attempting to access MySQL via the command line using the root user, the following error is encountered:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
Troubleshooting:
Solution:
If you have forgotten or lost the root password, the following steps can be taken to reset it:
Stop MySQL:
sudo service mysql stop
Restart MySQL with the --skip-grant-tables option:
mysqld_safe --skip-grant-tables &
Connect to MySQL without a password:
mysql -u root
Reset the root password:
For MySQL versions prior to 5.7:
UPDATE mysql.user SET Password=PASSWORD('new_password') WHERE User='root';
For MySQL version 5.7 and above:
UPDATE mysql.user SET authentication_string=PASSWORD('new_password') WHERE User='root';
Flush the privileges:
FLUSH PRIVILEGES;
Restart MySQL normally:
sudo service mysql start
Additional Tips:
The above is the detailed content of How to Troubleshoot MySQL Error 1045: Access Denied and Reset the Root Password?. For more information, please follow other related articles on the PHP Chinese website!