Change MySQL root password in phpMyAdmin

Change MySQL root password in phpMyAdmin

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Change MySQL root password in phpMyAdmin

When you secure your local development environment by setting a strong root password via the command line, accessing phpMyAdmin often breaks unexpectedly. The error "Access denied" is the immediate symptom of a configuration mismatch: phpMyAdmin still expects a blank password for the default root user, while your MySQL instance now requires authentication. Resolving this isn't about finding a magic button; it requires updating the PHP configuration file that controls how phpMyAdmin connects to the database server.

The standard approach involves modifying the config.inc.php file located in the system directory of your installation (e.g., C:\wamp\www\phpmyadmin\config.inc.php). You must add or uncomment specific lines to override the default credentials. The critical configuration block looks like this:

$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = 'YourNewStrongPassword';
$cfg['Servers'][$i]['AllowNoPasswordRoot'] = false;

Each line serves a distinct purpose. Setting auth_type to 'config' tells phpMyAdmin to ignore the default empty password and read credentials directly from the configuration file rather than relying on session-based or cookie-based authentication mechanisms. This is the most secure method for local development because it eliminates the risk of credential leakage through browser history or cookies.

The $cfg['Servers'][$i]['password'] line must match your current MySQL root password exactly. If this does not work, you might wonder if the AllowNoPasswordRoot flag is the culprit. While setting this to false disables legacy authentication methods where an empty password was accepted, modern versions of phpMyAdmin often default to 'config' authentication anyway. Therefore, ensuring auth_type is explicitly set is usually sufficient.

A common pitfall occurs when developers assume they can change the root password via phpMyAdmin itself while logged in as a standard user. This logic fails because changing the root account's password requires superuser privileges, which you cannot grant to a non-administrative MySQL user. You must perform the password change outside of phpMyAdmin using the MySQL command line or a GUI tool like Navicat or HeidiSQL.

Once the new password is set in the CLI, you update config.inc.php and restart your web server (Apache/Nginx) to ensure the PHP configuration cache is cleared. If you are using WAMP on Windows, simply opening the Control Panel and clicking "Restart All Services" is often enough.

For production environments or shared hosting scenarios where direct access to config.inc.php is restricted, this manual injection of credentials is not a viable option. In those cases, you would need to rely on .htaccess directives or server-level configurations like Apache's .userdir settings, which are beyond the scope of local WAMP setups. If you are managing a larger Laravel application hosted on a similar stack, ensuring your database credentials in your .env file match these configuration changes is equally critical for preventing runtime errors.

The trade-off here is that hardcoding credentials in config.inc.php makes them visible to anyone who can read the file on the server. In a local-only development environment like WAMP, this is generally acceptable, but it should never be pushed to a public web server without moving sensitive data into a .env file and excluding it from version control. Always verify that your config.inc.php changes are saved and that no syntax errors (like missing semicolons) are introduced, as these will prevent the entire PHP application from loading.

Our network