Home > Database > Mysql Tutorial > How Can I Quickly Fix the MySQL 'Access Denied for user 'root'@'localhost'' Error?

How Can I Quickly Fix the MySQL 'Access Denied for user 'root'@'localhost'' Error?

Mary-Kate Olsen
Release: 2025-01-21 00:56:08
Original
427 people have browsed it

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:

<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>
Copy after login

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".

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!

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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template