Home > Database > Mysql Tutorial > How to Fix MySQL Error 1045: Access Denied for User \'root\'@\'localhost\' (using password: YES)?

How to Fix MySQL Error 1045: Access Denied for User \'root\'@\'localhost\' (using password: YES)?

DDD
Release: 2024-10-26 07:43:02
Original
807 people have browsed it

How to Fix MySQL Error 1045: Access Denied for User 'root'@'localhost' (using password: YES)?

MySQL Error 1045: Troubleshooting and Resolution

Experiencing the error #1045, "Access denied for user 'root'@'localhost' (using password: YES)" when attempting to access MySQL using PHPMyAdmin can be frustrating. Here's a comprehensive guide to troubleshooting and resolving this issue:

Problem: Unable to log into MySQL using the mysql console due to an unknown password. PHPMyAdmin also returns an error message.

Solution:

  1. Retrieve MySQL Root Password:

    • Open a command prompt and run the following command:

      mysql -u root -p
      Copy after login
  2. Reset Root Password:

    • Type the existing password when prompted. If the password is blank, press Enter key.
    • Execute the following command to update the password:

      UPDATE mysql.user SET Password=PASSWORD('MyNewPass') WHERE User='root';
      Copy after login
    • Specify your desired new password in place of 'MyNewPass'.
  3. Update config.inc.php File:

    • Navigate to the config.inc.php file within your MySQL configuration directory.
    • Find the following line and replace the old password with the new password:

      $cfg['Servers'][$i]['password'] = 'MyNewPass';
      Copy after login
  4. Cycle MySQL Service:

    • Stop the MySQL service: mysql_stop.bat (Windows) or service mysql stop (Unix/Linux)
    • Start the MySQL service: mysql_start.bat (Windows) or service mysql start (Unix/Linux)

Additional Considerations for MySQL 5.7 and Higher:

If you are running MySQL version 5.7 or higher, use authentication_string instead of Password in the UPDATE query:

UPDATE mysql.user SET authentication_string=PASSWORD('MyNewPass') WHERE User='root';
Copy after login

By following these steps, you should be able to update your MySQL root password successfully and regain access to both the mysql console and PHPMyAdmin.

The above is the detailed content of How to Fix MySQL Error 1045: Access Denied for User \'root\'@\'localhost\' (using password: YES)?. 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