"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > Quickly resolve MySQL "root@localhost access denied" error

Quickly resolve MySQL "root@localhost access denied" error

Posted on 2025-04-18
Browse:946

How Can I Quickly Fix the MySQL

Solving the MySQL "Access Denied" Error for the 'root' User

The common MySQL error "Access denied for user 'root'@'localhost' (using password: YES)" often leads users down a rabbit hole of complicated solutions. Fortunately, a simple fix usually works.

Instead of complex troubleshooting, try this single query executed via sudo mysql:

ALTER USER 'root'@'localhost' 
IDENTIFIED WITH mysql_native_password 
BY 'root';

(Or, for MariaDB:)

ALTER USER 'root'@'localhost' 
IDENTIFIED VIA mysql_native_password 
USING PASSWORD('root');

This query performs two key functions:

  • Changes the authentication plugin: It switches to the mysql_native_password plugin.
  • Sets the root password: It sets the password to "root" (remember to replace 'root' with your chosen password within the query).

After running this query, you should be able to access your database as the root user. Consult the official MySQL or MariaDB documentation for further information.

To exit the MySQL console, press Ctrl D or type "exit".

Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3