In-depth Analysis and Solutions for 'Access Denied for User root@localhost' in PHPMyAdmin

Dec 07, 2025 · Programming · 9 views · 7.8

Keywords: PHPMyAdmin | MySQL Access Denied | Root Password Configuration

Abstract: This article explores the common error 'Access denied for user root@localhost' in PHPMyAdmin, identifying its root cause as improper or missing password settings in the configuration file. By detailing key parameters in config.inc.php, such as auth_type, user, and password, it provides a step-by-step configuration guide and emphasizes the role of the AllowNoPassword parameter. Additional factors like MySQL service status and firewall settings are discussed, with verification steps to ensure users can fully resolve access issues and enhance database management efficiency.

Error Analysis and Root Cause

When users set a root password in PHPMyAdmin and encounter the error message <span style="font-family: monospace;">#1045 - Access denied for user 'root'@'localhost' (using password: NO)</span>, this typically indicates that PHPMyAdmin failed to pass the password correctly to the MySQL server. The phrase <span style="font-family: monospace;">(using password: NO)</span> in the error suggests that PHPMyAdmin attempted the connection without using a password, even if one was set. The root cause lies in the PHPMyAdmin configuration file <span style="font-family: monospace;">config.inc.php</span>, where the password parameter is either incorrectly configured or missing, leading to authentication failure.

Configuration File Details and Fix Steps

PHPMyAdmin manages database connection settings through the <span style="font-family: monospace;">config.inc.php</span> file. Below is an analysis of key parameters and a configuration guide:

  1. Locate the Configuration File: In WAMP server, <span style="font-family: monospace;">config.inc.php</span> is usually located in the <span style="font-family: monospace;">C:\wamp\apps\phpmyadmin\</span> directory. Open this file using a text editor like Notepad++.
  2. Core Parameter Settings: Find the server configuration section in the file, often starting with <span style="font-family: monospace;">$cfg['Servers'][$i]</span>. Ensure the following parameters are correctly set:
    • <span style="font-family: monospace;">'auth_type' => 'config'</span>: This parameter specifies using the username and password from the configuration file for authentication, rather than cookie-based or other methods.
    • <span style="font-family: monospace;">'user' => 'root'</span>: Replace <span style="font-family: monospace;">'**your-root-username**'</span> with the actual root username, typically <span style="font-family: monospace;">'root'</span>.
    • <span style="font-family: monospace;">'password' => 'your_password_here'</span>: Replace <span style="font-family: monospace;">'**root-password**'</span> with the root password set in MySQL. For example, if the password is <span style="font-family: monospace;">mypass123</span>, set it as <span style="font-family: monospace;">'password' => 'mypass123'</span>.
    • <span style="font-family: monospace;">'AllowNoPassword' => true</span>: This parameter allows connections without a password, but it is recommended to change it to <span style="font-family: monospace;">false</span> after setting a password to enhance security. If left as <span style="font-family: monospace;">true</span>, it may mask configuration errors.
  3. Example Code: Below is a corrected configuration example, rewritten based on the best answer:
    $cfg['Servers'][$i]['verbose'] = 'localhost';
    $cfg['Servers'][$i]['host'] = 'localhost';
    $cfg['Servers'][$i]['port'] = '3306';
    $cfg['Servers'][$i]['socket'] = '';
    $cfg['Servers'][$i]['connect_type'] = 'tcp';
    $cfg['Servers'][$i]['extension'] = 'mysqli';
    $cfg['Servers'][$i]['auth_type'] = 'config';
    $cfg['Servers'][$i]['user'] = 'root';
    $cfg['Servers'][$i]['password'] = 'mypass123';
    $cfg['Servers'][$i]['AllowNoPassword'] = false;
    Note: In practice, replace <span style="font-family: monospace;">'mypass123'</span> with your actual password, and ensure quotes are used correctly.
  4. Save and Restart Services: After making changes, save the file and restart the WAMP server (or restart Apache and MySQL services separately) to apply the changes.

Other Potential Causes and Verification Steps

Beyond configuration file issues, other factors may contribute to this error. As supplementary references, consider the following aspects:

By following these steps, users should be able to resolve the access issue. If the error persists, check PHP error logs (located in the WAMP <span style="font-family: monospace;">logs</span> directory) for further debugging information.

Copyright Notice: All rights in this article are reserved by the operators of DevGex. Reasonable sharing and citation are welcome; any reproduction, excerpting, or re-publication without prior permission is prohibited.