Home >Database >Mysql Tutorial >How Can I Quickly Fix the MySQL 'Access Denied' Error for the Root User?
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:
<code class="language-bash">sudo mysql</code>
Next, execute the appropriate query within the MySQL console. Choose the query based on your database system:
For MySQL:
<code class="language-sql">ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';</code>
For MariaDB:
<code class="language-sql">ALTER USER 'root'@'localhost' IDENTIFIED VIA mysql_native_password USING PASSWORD('root');</code>
These commands perform two crucial actions:
mysql_native_password
.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!