Home > Database > Mysql Tutorial > How to Fix 'Access denied for user 'root@localhost' (using password:NO)' in Local WordPress MySQL?

How to Fix 'Access denied for user 'root@localhost' (using password:NO)' in Local WordPress MySQL?

Patricia Arquette
Release: 2024-12-11 18:40:13
Original
946 people have browsed it

How to Fix

MySQL Access Denied: 'Access denied for user 'root@localhost' (using password:NO)'

When attempting to run WordPress locally, you may encounter an error stating "Access denied for user 'root@localhost' (using password:NO)." This occurs when the MySQL root user password has not been set.

Steps to Resolve the Password Issue:

  1. Stop the MySQL Service:

    • Open the Windows Services window.
    • Find the MySQL service and stop it.
  2. Start MySQL without Privileges:

    • Open a command prompt as administrator.
    • Navigate to the MySQL bin directory (typically "C:Program FilesMySQLMySQL Server 5.1bin")
    • Run the following command:

      mysqld_safe --skip-grant-tables &
      Copy after login
  3. Enter MySQL Shell:

    • In a new terminal window, run:

      mysql -u root
      Copy after login
  4. Clear and Grant Privileges:

    • Use the following commands to clear the user table and grant root privileges:

      USE mysql;
      TRUNCATE TABLE user;
      FLUSH PRIVILEGES;
      GRANT ALL PRIVILEGES ON *.* TO root@localhost IDENTIFIED BY 'YourNewPassword' WITH GRANT OPTION;
      Copy after login
  5. Confirm Changes and Restart MySQL:

    • Exit MySQL and restart the service normally.
    • You should now be able to log in with the password you set.

Additional Notes:

  • If you do not want to set a password, use an empty string instead of 'YourNewPassword' in the GRANT command.
  • If you encounter an error stating "Access denied for user 'root@localhost' (using password:YES)", repeat the steps but enter "NO" instead of "YES" in the GRANT command.

The above is the detailed content of How to Fix 'Access denied for user 'root@localhost' (using password:NO)' in Local WordPress MySQL?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template