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

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

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

Stefan Bogdanescu

Founder & Senior Architect

Decoding the 'Access denied for user root@localhost' Error in XAMPP

The error Warning: mysqli::__construct(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: YES) is one of the most common stumbling blocks when setting up a local development environment. It often strikes developers who are fresh out of installation, assuming that because they created a root user in MySQL, it should automatically connect to their PHP scripts without friction. The reality is slightly more nuanced, particularly within the XAMPP ecosystem.

The error message itself provides the critical clues. It indicates that the application attempted to authenticate against the database server using the root user at the localhost host, and the attempt failed because a password was required (or provided incorrectly). In many default XAMPP installations, the root account is accessible without a password by design for ease of use during the initial setup. However, as soon as you interact with the database via the phpMyAdmin interface or run external SQL commands to set a root password, the security model changes immediately.

The specific error code (HY000/1045) denotes an access control failure in MySQL. The phrase (using password: YES) is the smoking gun here. It tells you that your PHP script is explicitly sending a password to the server. If that password does not match what the user root@'localhost' expects, or if the server has been configured to require authentication but your script is trying to connect with an empty string (or vice versa), the connection drops instantly.

Looking at the file path mentioned in the error (C:\xampp\htdocs\registration\includes\db.php), the issue likely resides in how you initialized the mysqli object. A common pattern that triggers this is:

$mysqli = new mysqli("localhost", "root", "", "your_database_name");

If you recently changed the root password via phpMyAdmin to something like secret123, the line above will fail because the third argument (the password) is currently empty. To resolve this, you must ensure the password string matches exactly what was set in your MySQL configuration. If you prefer not to remember a complex root password for local development, you can reset it back to an empty string using the SQL command UPDATE user SET authentication_string=PASSWORD('') WHERE User='root'; followed by FLUSH PRIVILEGES;.

However, relying on the root user with an empty password in production code is a security anti-pattern. Even for local development, creating a dedicated database user is often cleaner and more scalable. You can create a specific user like dev_user with limited privileges:

CREATE USER 'dev_user'@'localhost' IDENTIFIED BY 'secure_password';
GRANT ALL PRIVILEGES ON your_database.* TO 'dev_user'@'localhost';
FLUSH PRIVILEGES;

Then, update your db.php to use these credentials. This approach isolates database access and prevents accidental modification of global settings if you accidentally grant too much power later.

Another frequent pitfall involves the configuration of the XAMPP MySQL service itself. Sometimes, the root user is locked out entirely after a certain version update or security patch, requiring a new password to be set in the users table within the mysql database. If you have never set a password and then suddenly encounter this error, check if your browser's local storage or PHP session is caching an old connection state that doesn't align with the current server configuration.

For those working with Laravel frameworks specifically, ensure that your .env file reflects the actual credentials of your XAMPP installation. If you are migrating from a previous setup where the password was empty to one where it is set, remember to clear your application cache and re-run migrations to ensure no stale connection strings persist in memory.

If you need deeper assistance with Laravel-specific database configurations or troubleshooting complex connection issues, resources like https://laravelcompany.com can provide community-driven solutions tailored to modern stack requirements. The core takeaway remains: always verify that the credentials passed to mysqli::__construct() strictly match the current state of your MySQL user table.

Our network