Software⏱️ 2 min read📅 2026-05-31

How to Fix: mysql how to fix Access denied for user 'root'@'localhost'

MySQL Access denied error for root user at localhost.

Quick Answer: Re-enable the 'root' user by running the command 'mysql -u root -p' and then grant privileges to the new user, or use the 'mysqladmin' command to set the password for the 'root' user.

To resolve the 'Access denied for user ''root''@''localhost''' error, it's essential to understand the common causes behind this issue. The problem may arise from incorrect database privileges or an existing lock on the root account.

⚠️ Common Causes

  • Incorrect database privileges or an existing lock on the root account.

🚀 How to Resolve This Issue

Method 1: Resetting the Password

  1. Step 1: Open a new terminal or command prompt and type the following command to reset the root password: $ mysql -u root -p <password>

Method 2: Granting Privileges

  1. Step 1: Open the MySQL shell and type the following command to create a new user with full privileges: $ CREATE USER ''@'''' IDENTIFIED BY '' <password>;

✨ Wrapping Up

To avoid this issue in the future, ensure that you have a secure password for your root account and regularly update your MySQL privileges.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions