Home >Database >Mysql Tutorial >MySQL Error 1045: How to Fix 'Access Denied' for Root User?

MySQL Error 1045: How to Fix 'Access Denied' for Root User?

Patricia Arquette
Patricia ArquetteOriginal
2024-12-17 00:25:26515browse

MySQL Error 1045: How to Fix

MySQL: Access Denied Error 1045

Problem:

Users encounter the "ERROR 1045 - Access denied for user 'root'@'localhost' (using password: YES)" error when attempting to access MySQL through the command line. Despite uninstalling and reinstalling MySQL, resetting passwords, and following various guides, the issue persists.

Solution:

For users who have forgotten or lost their root password:

  1. Stop MySQL: Stop the MySQL service.
  2. Start MySQL with Skip-Grant Tables: Manually restart MySQL using the --skip-grant-tables option: mysqld_safe --skip-grant-tables.
  3. Connect with Root: Open a new terminal and connect to MySQL as root: mysql -u root.
  4. Reset Root Password: Reset the root password using the following MySQL command for MySQL versions prior to 5.7: UPDATE mysql.user SET Password=PASSWORD('password') WHERE User='root'; For MySQL version 5.7 and above: UPDATE mysql.user SET authentication_string=PASSWORD('password') WHERE User='root';.
  5. Flush Privileges: Flush the privileges to update the database table: FLUSH PRIVILEGES;.

Additional Tips:

  • Ensure that you have deleted all traces of MySQL after uninstalling it to ensure a fresh installation.
  • Refer to the provided link for additional details on resetting the root password.

The above is the detailed content of MySQL Error 1045: How to Fix 'Access Denied' for Root User?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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