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
:
<code class="language-sql">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');</code>
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".
The above is the detailed content of How Can I Quickly Fix the MySQL 'Access Denied for user 'root'@'localhost'' Error?. For more information, please follow other related articles on the PHP Chinese website!