How to fix "mysqli_sql_exception: Access denied for user '....'@'localhost' (using password: YES)" MySQL Error
What does this error mean?
This error appears when a website tries to connect to its database using a username and password that MySQL does not accept. The (using password: YES) part confirms a password was sent; it just didn't match what MySQL has on record for that user.
mysqli_sql_exception: Access denied for user 'db_username'@'localhost' (using password: YES)
This is almost always a mismatch between the database credentials stored in the site's configuration file and the actual password set on the database user; not a server-wide problem. It typically happens after a password reset, a site migration, a restore from backup, or a manual database change that wasn't reflected in the site's config file.
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Step 1: Confirm the database user still exists
i. Log in to cPanel.
ii. Go to Manage My Databases.
iii. Under Current Users, confirm the username from the error (for example, atest567_wp1) is listed.
If the user is missing entirely, it needs to be recreated and added to the correct database with the required privileges (Step 4 covers privileges).
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Step 2: Reset the database user's password
Since the exact previous password usually can't be retrieved, the reliable fix is to set a new one and update the site to match it.
i. In cPanel, go to Manage My Databases.
ii. Under Current Users, find the affected user and click Change Password.
iii. Set a new password. Avoid special characters like @, #, %, or $ unless you're certain the site's config file escapes them correctly; these are a common cause of this exact error.
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Step 3: Update the credentials in the site's configuration file
The new password now needs to match what the site is using to connect. Every website has a configuration file where the database username and password are stored — the exact file name varies by platform, but the update process is the same:
i. Open the site's configuration file via cPanel File Manager or FTP.
ii. Locate the line containing the database password.
iii. Replace it with the new password from Step 2.
iv. Save the file.
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Step 4: Confirm the user has privileges on the database
A correct password with no privileges on the database produces the same error.
i. In cPanel, go to Manage My Databases.
ii. Scroll to Current Databases. This table lists each database along with its Privileged Users column; the affected user should appear here as a link next to the correct database.
iii. If the user is not listed under Privileged Users for that database, scroll to Add User to Database, select the user and the database, click Add, then grant All Privileges on the next screen.
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Step 5: Check the database host value
The config file also stores a database host, and it isn't always localhost; the error message showing @'localhost' reflects where the connection was attempted from, not necessarily what the config file should say. On some setups (remote MySQL, certain migrations, or a database hosted on a separate server), the correct host is an IP address or a specific hostname instead.
i. Open the site's configuration file again.
ii. Locate the database host field (commonly DB_HOST or similar, alongside the username and password).
iii. If the site's database is on a remote or separate MySQL server, confirm the correct host value with the hosting setup rather than assuming localhost; an incorrect host here can produce the same access denied error even with the right username and password.
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Step 6: Test the connection
Reload the site. If the error persists:
- Double-check for typos or extra spaces in the username, password, or database name in the config file; a single stray character will cause this.
- Confirm the database name in the config file matches the actual database name exactly (cPanel usually prefixes database and user names with the cPanel account name, e.g., cpses_dbname).
- If the password contains special characters, try resetting it to a simple alphanumeric password to rule out an escaping issue in the config file.
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Preventing this in the future
- After resetting any database user's password, immediately update every config file that connects with that user.
- Avoid special characters in database passwords unless the application is confirmed to handle them correctly.
- Keep a record of which config files use which database credentials, especially on sites with multiple databases.