Home >Database >Mysql Tutorial >How to Resolve MySQL Error: 'Access Denied for User 'root'@'localhost''?
Troubleshooting MySQL Error: "Access Denied for user 'root'@'localhost'"
Encountering the "Access denied for user 'root'@'localhost'" error in MySQL? This means your MySQL server is blocking login attempts from the root user. This is often due to incorrect credentials or misconfigured settings.
Resolution:
Use the MySQL console (access via sudo mysql
) to run this SQL command:
<code class="language-sql">-- For MySQL ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_new_password'; -- For MariaDB ALTER USER 'root'@'localhost' IDENTIFIED VIA mysql_native_password USING PASSWORD('your_new_password');</code>
Replace 'your_new_password'
with your chosen password. This command switches the authentication plugin to mysql_native_password
and sets a new password.
After executing the command, close the MySQL console and try logging in again with the root user and your new password. The connection should now be successful.
Important Considerations:
The above is the detailed content of How to Resolve MySQL Error: 'Access Denied for User 'root'@'localhost''?. For more information, please follow other related articles on the PHP Chinese website!