ERROR 1045 (28000): Access denied for user 'acmecorp_app'@'localhost' (using password: YES) is one of MySQL’s most common error messages and one of the most ambiguous. It can mean wrong password, but it can also mean the user doesn’t exist for that host, has no grants on the database, or that the connection isn’t going where you think it is. The error doesn’t distinguish. A cPanel admin who knows the failure modes in order finds the cause in two minutes; a guess-and-check approach can take an hour.
What’s happening
MySQL’s authentication has multiple layers:
- Does the user exist?
'user'@'host'is the identity.'acmecorp_app'@'localhost'and'acmecorp_app'@'%'are different users; both might exist, neither might, or only one. The mismatch is the most common Access denied root cause. - Is the password right? Authentication compares the supplied password against
mysql.user.authentication_string(orPasswordon legacy). cPanel-set passwords usually use the modern hash; manually-set ones via raw SQL may use a deprecated hash that the client refuses. - Does the user have any grants? A user with no grants gets “Access denied” the moment they try to USE a database — even though they technically authenticated.
- Is the host matching? A connection from
127.0.0.1matches'@localhost'(via the Unix socket) but a TCP connection to127.0.0.1:3306matches'@127.0.0.1'. If the user only haslocalhost, TCP connections fail. - Is the connection going where you think? A PHP app with
DB_HOST = 'localhost'uses the Unix socket;DB_HOST = '127.0.0.1'uses TCP. Different paths, possibly different users matched. - Is the port right? cPanel default is 3306. If MySQL has been moved (rare on cPanel), the client’s port assumption is wrong.
How to verify
mysql -e "SELECT User, Host FROM mysql.user WHERE User='acmecorp_app'"
mysql -e "SHOW GRANTS FOR 'acmecorp_app'@'localhost'"
mysql -e "SHOW GRANTS FOR 'acmecorp_app'@'%'"
mysql -u acmecorp_app -p -h localhost -e "SELECT USER(), CURRENT_USER()"
mysql -u acmecorp_app -p -h 127.0.0.1 -e "SELECT USER(), CURRENT_USER()"
ss -tlnp | grep mysql
grep DB_HOST /home/acmecorp/public_html/wp-config.php
USER() returns what the client sent; CURRENT_USER() returns what MySQL matched. The difference is the diagnostic — if you sent acmecorp_app@anything and MySQL matched you as ''@anonymous, your user doesn’t have an entry for the actual source host.
The fix
- Confirm the user-host combination exists:
If onlySELECT User, Host FROM mysql.user WHERE User='acmecorp_app''acmecorp_app'@'localhost'exists and the app connects via TCP, that’s the first thing to fix. Either add'acmecorp_app'@'127.0.0.1', or changeDB_HOSTtolocalhost. - Test authentication directly:
Type the password. If this works, the user and password are fine; the app config is the issue.mysql -u acmecorp_app -p -h localhost -e "SELECT USER()" - If wrong password, reset via cPanel API (don’t use raw SQL — see grants article):
This updates both MySQL and the cPanel dbmap.uapi --user=acmecorp Mysql set_password user=acmecorp_app password='new-strong-password' - For missing grants:
uapi --user=acmecorp Mysql set_privileges_on_database user=acmecorp_app database=acmecorp_app privileges=ALL - For host mismatches — if the app connects from a non-localhost address (rare on cPanel but happens in remote MySQL setups), the cPanel Remote MySQL UI adds the host. Or via API:
uapi --user=acmecorp Mysql add_host user=acmecorp_app host=203.0.113.42 - For “the password is right but it still fails”, check the plugin column:
IfSELECT User, Host, plugin FROM mysql.user WHERE User='acmecorp_app'pluginismysql_native_passwordand the client only supportscaching_sha2_password(MySQL 8.0 default), or vice versa, the client and server disagree on auth method. Modern cPanel + MariaDB defaults tomysql_native_passwordwhich most clients support. MySQL 8.0 needs explicit alignment. - For the persistent “Access denied” after all the above checks, look at
journalctl -u mariadb | grep "Access denied"— MySQL logs each denied attempt with the reason (wrong password, user doesn’t exist, account locked, expired password).
For multi-tenant cPanel hosts where grant troubleshooting happens often, Stack Harbor’s cPanel server management team standardizes the checklist and runs it as the first response to any “I can’t connect to the database” ticket.