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:
mysql_native_password
plugin.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".
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