Home >Database >Mysql Tutorial >MySQL ERROR 1045: How to Fix 'Access Denied' Even After Password Reset?

MySQL ERROR 1045: How to Fix 'Access Denied' Even After Password Reset?

Linda Hamilton
Linda HamiltonOriginal
2024-12-05 07:55:10198browse

MySQL ERROR 1045: How to Fix

MySQL: Troubleshooting ERROR 1045 "Access denied"

Error Encountered:

Upon attempting to access MySQL using the command line, a user receives the following error:

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

Cause:

This error indicates that the MySQL server is denying access to the specified user (usually "root") with the given password.

Solution:

Since password resetting has proven ineffective, a more thorough approach is required.

Reinstalling MySQL with Complete Removal

  1. Completely Uninstall MySQL:
    Ensure that all MySQL files and directories are completely removed.
  2. Restart the System:
    Reboot the system to clear any residual memory.
  3. Reinstall MySQL:
    Freshly install MySQL, ensuring a default installation.

Additional Tips

  • Skip Grant Tables:
    If you have forgotten your root password, you can restart MySQL with the --skip-grant-tables option to temporarily disable access restrictions.
  • Reset Root Password:
    While MySQL is running with --skip-grant-tables, connect to the MySQL client and reset the root password. For MySQL 5.7 or later, use the following command:

    UPDATE mysql.user SET authentication_string=PASSWORD('new_password')  WHERE  User='root';
  • Flush Privileges:
    After resetting the password, flush the privileges to ensure the changes take effect:

    FLUSH PRIVILEGES;

By following these steps, you can resolve the "Access denied" error and regain access to your MySQL server with a default installation.

The above is the detailed content of MySQL ERROR 1045: How to Fix 'Access Denied' Even After Password Reset?. 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