![Why Is MySQL Access Denied for User 'root@localhost' (Using Password: NO or YES)?](https://img.php.cn/upload/article/000/000/000/173484064991332.jpg)
MySQL Error: Access Denied for User 'root@localhost' (Using Password: NO)
Problem:
When attempting to run WordPress on a Windows desktop, MySQL is required. However, without setting a root password during installation, WordPress asks for one upon installation. Attempts to access MySQL with a default password or without a password using mysql -u root -p result in access being denied.
Potential Resolution:
The user may not have set a root password for MySQL during installation. To resolve this issue, follow the steps below:
-
Stop the MySQL Service: Stop the MySQL service in Windows services.
-
Open Command Prompt: Open an elevated command prompt.
-
Change Directory: Navigate to the MySQL bin directory: c:program filesmysqlbin.
-
Execute the Command: Run the following command, replacing "C:root.txt" with the path to a file containing the root password (if any):
-
Start the MySQL Service: Restart the MySQL service in Windows services.
-
Enter Password: Type mysql -u root -p in the command prompt and enter the root password when prompted.
Update:
Even after following the above steps, access may still be denied with the error message:
"Access denied for user 'root@localhost' (using password:YES)"
Additional Solution:
To fix this error, reset the root user's password using the following steps:
-
Restart MySQL in Safe Mode: Stop the MySQL service, then start it without any privileges using mysqld_safe --skip-grant-tables &.
-
Connect to MySQL: Enter the MySQL command prompt: mysql -u root.
-
Reset Password: Use the following commands to reset the password:
-
Restart MySQL Normally: Kill the mysqld_safe process and the MySQL process, then start MySQL in normal mode.
-
Test Access: Connect to MySQL with the root password set in step 3, e.g., mysql -u root -pYourNewPassword. Access should now be granted.
The above is the detailed content of Why Is MySQL Access Denied for User 'root@localhost' (Using Password: NO or YES)?. For more information, please follow other related articles on the PHP Chinese website!