Home > Database > Mysql Tutorial > How to Troubleshoot MySQL Error 1045: Access Denied and Reset the Root Password?

How to Troubleshoot MySQL Error 1045: Access Denied and Reset the Root Password?

DDD
Release: 2024-12-16 00:46:11
Original
122 people have browsed it

How to Troubleshoot MySQL Error 1045: Access Denied and Reset the Root Password?

MySQL - ERROR 1045: Access Denied - Troubleshooting and Resetting Root Password

Problem:

When attempting to access MySQL via the command line using the root user, the following error is encountered:

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

Troubleshooting:

  • Verify that the correct root password is being used.
  • Check that MySQL is listening on the correct port (default is 3306).
  • Ensure that the MySQL server is running.

Solution:

If you have forgotten or lost the root password, the following steps can be taken to reset it:

  1. Stop MySQL:

    sudo service mysql stop
    Copy after login
  2. Restart MySQL with the --skip-grant-tables option:

    mysqld_safe --skip-grant-tables &
    Copy after login
  3. Connect to MySQL without a password:

    mysql -u root
    Copy after login
  4. Reset the root password:
    For MySQL versions prior to 5.7:

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

    For MySQL version 5.7 and above:

    UPDATE mysql.user SET authentication_string=PASSWORD('new_password') WHERE User='root';
    Copy after login
  5. Flush the privileges:

    FLUSH PRIVILEGES;
    Copy after login
  6. Restart MySQL normally:

    sudo service mysql start
    Copy after login

Additional Tips:

  • Always ensure a strong root password for improved security.
  • Remove any leftover MySQL files after uninstalling to avoid conflicts during reinstallation.

The above is the detailed content of How to Troubleshoot MySQL Error 1045: Access Denied and Reset the 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