Software⏱️ 3 min read📅 2026-06-03

How to Fix: Access denied for user 'root'@'localhost' while attempting to grant privileges. How do I grant privileges?

MySQL access denied for root@localhost with privileges to grant privileges

Quick Answer: Check if the MySQL server is set to use a password authentication method instead of public key authentication.

The error 'Access denied for user 'root'@''localhost'' while attempting to grant privileges' occurs when the MySQL server denies access to the root user, despite having already granted access. This issue affects users who are trying to manage their MySQL server's privileges.

This error can be frustrating as it prevents users from performing essential tasks such as granting or revoking privileges. In this guide, we will walk through the possible causes of this error and provide two primary methods for resolving the issue.

🔍 Why This Happens

  • The first main reason why this error happens is due to a mismatch between the MySQL server's configuration and the user's connection settings. When a user tries to connect to the MySQL server using an SSH client, the connection settings are not properly configured, leading to authentication errors.
  • Another alternative cause of this error could be related to the MySQL server's security settings or the user's account status. In some cases, the root user may have been locked out due to incorrect password attempts or other security measures.

🚀 How to Resolve This Issue

Granting Privileges Using a Different Command

  1. Step 1: To resolve this issue using method 1, you will need to use the `GRANT` command with the `RELOAD` option. This command allows you to grant privileges without restarting the MySQL server.
  2. Step 2: First, log in to your MySQL client and execute the following command: `GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH RELOAD;`
  3. Step 3: Next, flush the privileges by executing the following command: `FLUSH PRIVILEGES;`

Granting Privileges Using a Restart

  1. Step 1: Alternatively, you can also grant privileges by restarting the MySQL server. This method is useful when using older versions of MySQL that do not support the `RELOAD` option.
  2. Step 2: To use this method, execute the following command: `service mysql restart;` or `sudo systemctl restart mysql;` (depending on your system's configuration)
  3. Step 3: After the MySQL server has restarted, you can verify that the privileges have been granted by logging in to the MySQL client and executing the same `GRANT` command used earlier

🎯 Final Words

To summarize, the error 'Access denied for user ''@'' while attempting to grant privileges' occurs due to a mismatch between the MySQL server's configuration and the user's connection settings. By using either method 1 or method 2, you can successfully grant privileges to the root user and regain access to your MySQL server.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions