Skip to content

Troubleshooting MySQL grants for a cPanel account user when the application says Access denied

A connection-level Access denied has six common root causes. Walking them in order — wrong password, wrong host, missing user, no grants, wrong database, wrong port — finishes the triage fast.

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:

  1. 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.
  2. Is the password right? Authentication compares the supplied password against mysql.user.authentication_string (or Password on legacy). cPanel-set passwords usually use the modern hash; manually-set ones via raw SQL may use a deprecated hash that the client refuses.
  3. 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.
  4. Is the host matching? A connection from 127.0.0.1 matches '@localhost' (via the Unix socket) but a TCP connection to 127.0.0.1:3306 matches '@127.0.0.1'. If the user only has localhost, TCP connections fail.
  5. 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.
  6. 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

  1. Confirm the user-host combination exists:
    SELECT User, Host FROM mysql.user WHERE User='acmecorp_app'
    If only '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 change DB_HOST to localhost.
  2. Test authentication directly:
    mysql -u acmecorp_app -p -h localhost -e "SELECT USER()"
    Type the password. If this works, the user and password are fine; the app config is the issue.
  3. If wrong password, reset via cPanel API (don’t use raw SQL — see grants article):
    uapi --user=acmecorp Mysql set_password user=acmecorp_app password='new-strong-password'
    This updates both MySQL and the cPanel dbmap.
  4. For missing grants:
    uapi --user=acmecorp Mysql set_privileges_on_database user=acmecorp_app database=acmecorp_app privileges=ALL
  5. 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
  6. For “the password is right but it still fails”, check the plugin column:
    SELECT User, Host, plugin FROM mysql.user WHERE User='acmecorp_app'
    If plugin is mysql_native_password and the client only supports caching_sha2_password (MySQL 8.0 default), or vice versa, the client and server disagree on auth method. Modern cPanel + MariaDB defaults to mysql_native_password which most clients support. MySQL 8.0 needs explicit alignment.
  7. 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.