Home > Database > Mysql Tutorial > How Can I Quickly Fix the MySQL 'Access Denied' Error for the Root User?

How Can I Quickly Fix the MySQL 'Access Denied' Error for the Root User?

Linda Hamilton
Release: 2025-01-21 00:47:09
Original
890 people have browsed it

How Can I Quickly Fix the MySQL

A Simple Fix for the MySQL "Access Denied" Error

Encountering the dreaded "Access denied for user 'root'@'localhost'" error in MySQL? This guide offers a quick and easy solution, avoiding the complex procedures often found online.

Here's how to resolve this issue:

First, access the MySQL console using the following command:

sudo mysql
Copy after login

Next, execute the appropriate query within the MySQL console. Choose the query based on your database system:

For MySQL:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';
Copy after login

For MariaDB:

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

These commands perform two crucial actions:

  • They change the authentication plugin to mysql_native_password.
  • They set the root password to 'root' (you can easily change this to your desired password within the query).

After running the command, you should be able to log in using the root user and your new password.

For comprehensive details, consult the official MySQL or MariaDB documentation. 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' Error for the Root User?. For more information, please follow other related articles on the PHP Chinese website!

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