Home >Database >Mysql Tutorial >How to Fix 'Access denied for user 'root@localhost'' MySQL Error?
This error occurs when attempting to access the MySQL server as the 'root' user without a password or using an incorrect one.
To resolve this issue, follow these steps:
Reset the Root Password:
Execute the following command:
mysqld --defaults-file="C:\program files\MySQL\MySQL Server 5.1\my.ini" --init-files=C:\root.txt
Connect to MySQL: Open CMD and type the following:
mysql -u root -p
Enter the password you set in step 2.
Grant Privileges: If you encounter the error "Access denied for user 'root@localhost' (using password:YES)", use the following command to grant all privileges to the root user:
GRANT ALL PRIVILEGES ON *.* TO root@localhost IDENTIFIED BY 'YourNewPassword' WITH GRANT OPTION;
Flush the privileges with:
FLUSH PRIVILEGES;
You should now be able to successfully log in to MySQL as the 'root' user using the password you set.
The above is the detailed content of How to Fix 'Access denied for user 'root@localhost'' MySQL Error?. For more information, please follow other related articles on the PHP Chinese website!