Mysqli_real_connect(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: NO)

Mysqli_real_connect(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: NO)

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

Stefan Bogdanescu

Founder & Senior Architect

Decoding mysqli_real_connect(): Access denied for user 'root'@'localhost'

The error message mysqli_real_connect(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: NO) is one of the most common stumbling blocks for developers setting up a local environment. It indicates that the PHP application attempted to establish a connection to the MySQL server but was rejected by the database engine itself. The specific suffix (using password: NO) is often misunderstood; it does not necessarily mean the user has no password set, but rather that the credentials provided in the configuration file did not match what the MySQL server expects for that specific user and host combination.

In the scenario described, you have XAMPP installed with a manually created database where root was assigned the password 123456789. When phpMyAdmin fails to connect, it is attempting to validate its own credentials against the MySQL server's internal account table. If the server rejects the connection with "Access denied," the mismatch usually lies in the authentication method or the specific user entry in the mysql.user system table.

Understanding the Authentication Mismatch

Modern versions of MySQL (5.7 and later, especially 8.0) utilize a plugin-based authentication system. By default, XAMPP installations often configure the root user to use the mysql_native_password plugin. However, if you have previously reset this password using an older method or via command-line tools that default to auth_socket (common on Linux/Unix systems) or caching_sha2_password, a conflict arises.

phpMyAdmin typically expects the standard mysql_native_password. If your local root user is configured with a different plugin, or if the password hash in the database does not match the plain text string you think it is, the connection fails. Even though you believe you set the password to 123456789, MySQL stores this as a cryptographic hash. If the client library tries to authenticate using a protocol the server doesn't expect for that user, or if the stored hash is incompatible with the current PHP configuration, you get the access denied error.

Resolving the Configuration on Local Environments

The advice to edit config.inc.php is standard, but as you noted, permission errors on macOS can hinder this approach. While XAMPP for Mac is often installed in /Applications/XAMPP/, the actual configuration file for phpMyAdmin might be located in the htdocs directory or a separate config path depending on your specific installation layout.

If you cannot edit the file directly due to permissions, do not force yourself to become a superuser if it introduces security risks or complexity. Instead, verify the actual location of the config.inc.php file within your XAMPP installation and ensure you have write access to that specific directory. You can often change permissions using chmod 644 config.inc.php or by moving the file to a location where you have full control.

Once accessible, locate the $cfg['Servers'][$i]['auth_type'] setting. Ensure it is set to cookie or http. Then, explicitly define the password:

$cfg['Servers'][$i]['password'] = '123456789';

It is also prudent to check the $cfg['Servers'][$i]['host'] setting. Ensure it points to localhost and not a Unix socket path that your application isn't configured to use.

Alternative Approaches for Java Development

Since your ultimate goal is to build a login form in Java, relying on phpMyAdmin's configuration files is irrelevant to the Java application itself. The error you are troubleshooting regarding phpMyAdmin is separate from how your Java app will connect. For Java, you should focus on the JDBC connection string and driver compatibility rather than trying to fix the web server's config file.

When connecting via JDBC, the user and password properties in the URL must match exactly what exists in the MySQL database. If you are using a local XAMPP setup, ensure the MySQL service is running before attempting the connection. If you prefer not to use root for your application due to security best practices, consider creating a dedicated user with restricted privileges via the command line:

mysql -u root -p
CREATE USER 'app_user'@'localhost' IDENTIFIED BY 'secure_password';
GRANT SELECT, INSERT, UPDATE, DELETE ON your_database.* TO 'app_user'@'localhost';
FLUSH PRIVILEGES;

This approach decouples your application's security from the administrative root account. Remember that while local development allows for loose configurations, production environments should always enforce strict password hashing and minimal privilege grants. The error you encountered is a valuable lesson in verifying that the client (phpMyAdmin or Java) speaks the same authentication language as the server.

Our network