Home > Database > Mysql Tutorial > How to Fix \'Access denied for user \'root\'@\'localhost\' (using password: NO)\' Error When Resetting MySQL Root Password?

How to Fix \'Access denied for user \'root\'@\'localhost\' (using password: NO)\' Error When Resetting MySQL Root Password?

DDD
Release: 2024-11-03 21:16:29
Original
655 people have browsed it

How to Fix

Troubleshooting Access Denied Error for 'root'@'localhost'

Scenario:

When attempting to reset the password for the MySQL user 'root', you encounter the error:

Access denied for user 'root'@'localhost' (using password: NO)
Copy after login

Investigation:

This error indicates a permissions issue preventing you from modifying user settings. The error occurs despite you having granted all privileges to 'root'@'localhost'.

Solution:

To resolve this issue, follow these steps:

  1. Reconnect to MySQL using the existing credentials:
$ mysql -u root -p
Copy after login
  1. Enter the current password.
  2. For security reasons, MySQL masks the password prompt with asterisks, so you need to type the password blindly (which will appear as a blank line).
  3. Type the following command as a single line:
mysqladmin -u root -p password foo
Copy after login
  1. The prompt will ask you to confirm the new password. Enter it twice.

Explanation:

The command mysqladmin allows you to configure MySQL server settings without logging in. In this case, the -p option prompts for a password, and the password argument specifies that we are setting the user's password. The word "password" in the command should be typed literally, as it's a command and not the actual password itself.

The above is the detailed content of How to Fix \'Access denied for user \'root\'@\'localhost\' (using password: NO)\' Error When Resetting MySQL Root Password?. 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template