Skip to content

MySQL "ERROR 1045: Access denied for user" on cPanel — password, host, or wrong account

ERROR 1045 reads like a wrong password, but a MySQL account is the pair user@host. Read the error literally, then work down a fixed order: empty password, missing account, cPanel prefix, localhost versus 127.0.0.1, drifted password, missing grant, authentication plugin.

ERROR 1045 (28000): Access denied for user 'user'@'host' (using password: YES) is MySQL answering and refusing. The server is healthy, it received your credentials, and it decided they do not match an account allowed to connect from where you are connecting. The trap is that 1045 reads like “wrong password”, but a MySQL account is the pair 'user'@'host' — so the host half is just as often the culprit, and localhost and 127.0.0.1 are different host values that can select different rows with different passwords. On cPanel the database user and the database name are both prefixed with the cPanel account name, which adds two more ways to get the string slightly wrong. Read the error literally: it prints the exact user and host MySQL evaluated, and the fix is almost always making a real account match that pair.

What you’ll accomplish

  • Extract three facts from the error line itself: which account name was tried, which host value MySQL resolved the connection to, and whether a password was sent at all.
  • Prove whether the failure is in MySQL or in the application, by reproducing the connection with the mysql client before touching a config file.
  • Work through the causes in a fixed order instead of guessing: empty password, missing account, missing cPanel prefix, host mismatch, drifted password, plugin mismatch.
  • Tell a 1045 (login refused) apart from a 1044 (login fine, no rights on the database) so you fix the right layer.
  • End with a verified connection using the application’s own user, host, and database name.

Prerequisites

  • A cPanel/WHM server running MySQL 8.0 or MariaDB 10.3 or newer. Most cPanel installations run MariaDB; the SQL below notes where the two diverge.
  • Root shell access for the diagnostic queries. Everything except reading mysql.user can be done from the cPanel account instead.
  • The cPanel account name, because it is the prefix on both the database user and the database name. The placeholders here are cpuser for the account, cpuser_wp for the database user, and cpuser_wpdb for the database.
  • Passwords below are always the literal placeholder REPLACE_WITH_A_REAL_PASSWORD. Never paste a real one into a shell command other users can read in ps.
  • WP-CLI if the affected application is WordPress. It ships on most cPanel servers as wp.
  • A quiet window before changing a password: every worker and cron job holding the old one fails the moment you change it.

How it works

A MySQL account is not a username. It is the pair 'user'@'host', and 'wpuser'@'localhost', 'wpuser'@'127.0.0.1' and 'wpuser'@'%' are three separate accounts that can carry three different passwords and three different sets of privileges. When a client connects, the server takes the username it was given and the host it sees the connection arriving from, sorts the candidate rows most-specific-first, and picks the first match. Only then does it check the password — against that row, and no other.

Diagram showing an incoming MySQL connection matched against four candidate rows in mysql.user, the host-matching step selecting one row, and the password being checked against that row alone

That ordering is the whole insight. If your application connects to 127.0.0.1 but the only grant is for localhost, MySQL is not comparing your password against the account you think it is: it falls through to a wildcard row with a different password, or finds nothing at all. Either way you get 1045 while holding a password that is genuinely correct. The distinction is real at the transport level too — localhost in the MySQL client means “use the UNIX socket”, while 127.0.0.1 forces TCP to port 3306 — so changing one word in wp-config.php changes both the transport and the account row.

The second half of the error line is a fact you get for free. using password: YES means the client sent something; NO means it sent an empty string. A config that lost its credentials produces NO, and no amount of password resetting helps until the config is repaired. MySQL’s reference covers the full matching rules in Access Control, Stage 1: Connection Verification.

cPanel adds two prefixes on top of this. A database user created through cPanel is stored as cpuser_wp, not wp, and the database as cpuser_wpdb, not wpdb — the interface shows the short name you typed while the real object carries the prefix. An application configured with the short name authenticates as an account that does not exist: a 1045 with a perfectly correct password. The prefix rules are covered in database and user prefixes on cPanel.

Step-by-step

  1. Read the error literally and reproduce it with the mysql client. Before editing anything, take the exact user, host, and database name out of the application config and make the same connection by hand. That is what separates a MySQL problem from a PHP one.

    mysql -u cpuser_wp -p -h 127.0.0.1 cpuser_wpdb

    The failure you are chasing looks like this, and every field in it is evidence:

    Enter password:
    ERROR 1045 (28000): Access denied for user 'cpuser_wp'@'127.0.0.1' (using password: YES)

    Three facts: the account tried was cpuser_wp, the host MySQL resolved was 127.0.0.1, and a password was sent. Follow the branch that matches your own error line.

    Decision tree starting from the ERROR 1045 text, branching on using password NO, whether the user-host row exists, whether the password matches, and whether the denial is on the database rather than the login

  2. If the error says using password: NO, repair the config, not the account. An empty password reached the server. Read the four values the application is actually sending:

    grep -nE "DB_NAME|DB_USER|DB_HOST|DB_PASSWORD" /home/cpuser/public_html/wp-config.php

    The bug is visible on one line:

    23:define( 'DB_NAME', 'cpuser_wpdb' );
    26:define( 'DB_USER', 'cpuser_wp' );
    29:define( 'DB_PASSWORD', '' );
    32:define( 'DB_HOST', 'localhost' );

    Put the real password back into that constant. If you are unsure the file you edited is the one WordPress reads, ask WP-CLI instead:

    wp config get DB_USER --path=/home/cpuser/public_html
    wp config get DB_HOST --path=/home/cpuser/public_html
    cpuser_wp
    localhost
  3. List the accounts that actually exist, prefix included. As root, ask MySQL which rows are really there, not which ones you remember creating:

    mysql -e "SELECT user, host, plugin FROM mysql.user WHERE user LIKE 'cpuser%' ORDER BY user, host;"
    +-----------+-----------+-----------------------+
    | user      | host      | plugin                |
    +-----------+-----------+-----------------------+
    | cpuser_wp | localhost | mysql_native_password |
    +-----------+-----------+-----------------------+

    Do the same for the database name, since a typo there fails the same way:

    mysql -e "SHOW DATABASES LIKE 'cpuser%';"
    +--------------------+
    | Database (cpuser%) |
    +--------------------+
    | cpuser_wpdb        |
    +--------------------+

    Compare both against what step 2 printed. If the config says wp and wpdb while MySQL says cpuser_wp and cpuser_wpdb, you have found it: set the prefixed names and stop here. Without root, the same list is on the cPanel MySQL Databases page.

  4. Match the host half. The output above shows one row, scoped to localhost; an application pointed at 127.0.0.1 will never match it. Prove the asymmetry by running both connections back to back:

    mysql -u cpuser_wp -p -h localhost cpuser_wpdb -e "SELECT 1;"
    mysql -u cpuser_wp -p -h 127.0.0.1 cpuser_wpdb -e "SELECT 1;"

    The first returns a one-row result, the second returns 1045 with the same password:

    +---+
    | 1 |
    +---+
    | 1 |
    +---+
    ERROR 1045 (28000): Access denied for user 'cpuser_wp'@'127.0.0.1' (using password: YES)

    The clean fix on cPanel is to point the application at localhost, the host cPanel scopes its users to:

    wp config set DB_HOST localhost --path=/home/cpuser/public_html

    WP-CLI answers with a Success: line naming the constant it updated. If the application must use TCP — a container, or a client library that ignores sockets — create the matching account instead:

    mysql -e "CREATE USER 'cpuser_wp'@'127.0.0.1' IDENTIFIED BY 'REPLACE_WITH_A_REAL_PASSWORD';"
    mysql -e "GRANT ALL PRIVILEGES ON cpuser_wpdb.* TO 'cpuser_wp'@'127.0.0.1';"

    Both statements print nothing on success. A user created this way exists in MySQL but not in cPanel’s own record of it, so prefer the cPanel interface where it can express what you need.

  5. Reset a drifted password with ALTER USER. After a cPanel password change, a restore, or a transfer between servers, the stored hash and the config can disagree. Set a known value:

    mysql -e "ALTER USER 'cpuser_wp'@'localhost' IDENTIFIED BY 'REPLACE_WITH_A_REAL_PASSWORD';"

    Silence is success; mysql -e prints nothing for a statement that worked. ALTER USER is the current form on MySQL 5.7.6 and later and MariaDB 10.2 and later; the older SET PASSWORD FOR 'cpuser_wp'@'localhost' = PASSWORD('...'); still works on older MariaDB but is gone from MySQL 8. You do not need FLUSH PRIVILEGES after ALTER USER, CREATE USER or GRANT — the server reloads its in-memory grants itself. It is only required after editing the grant tables directly with UPDATE or INSERT, which you should not be doing. Then put the same value into the application config and into any cron job or worker carrying its own copy.

  6. Separate a 1045 from a 1044. If the login succeeds but the session is refused on the database, the error number changes and so does the fix. Look at what the account may actually do:

    mysql -e "SHOW GRANTS FOR 'cpuser_wp'@'localhost';"
    +-------------------------------------------------+
    | Grants for cpuser_wp@localhost                   |
    +-------------------------------------------------+
    | GRANT USAGE ON *.* TO `cpuser_wp`@`localhost`    |
    +-------------------------------------------------+

    USAGE ON *.* and nothing else means the account can log in and do nothing, which surfaces as a different error entirely:

    ERROR 1044 (42000): Access denied for user 'cpuser_wp'@'localhost' to database 'cpuser_wpdb'

    That is a privilege problem, not an authentication one. Attach the user to the database in cPanel, or grant it directly:

    mysql -e "GRANT ALL PRIVILEGES ON cpuser_wpdb.* TO 'cpuser_wp'@'localhost';"

    Re-running SHOW GRANTS should now list a second line for cpuser_wpdb.*.

  7. Check the authentication plugin, and know which server you are on. The plugin column tells you how the account expects to prove itself. Two traps live here, and they belong to different servers:

    mysql -e "SELECT user, host, plugin FROM mysql.user WHERE user IN ('root','cpuser_wp');"
    +-----------+-----------+-----------------------+
    | user      | host      | plugin                |
    +-----------+-----------+-----------------------+
    | root      | localhost | unix_socket           |
    | cpuser_wp | localhost | mysql_native_password |
    +-----------+-----------+-----------------------+

    On MariaDB, unix_socket on root@localhost means the account is proved by the operating-system user you are running as, not by a password: mysql -u root -p as any other OS user fails no matter what you type. Run it as root, or sudo mysql. On MySQL 8, the default plugin is caching_sha2_password, and an old client or PHP extension that cannot speak it fails — but usually with ERROR 2054 or ERROR 2059, not 1045. The number is how you tell them apart: a 2000-series error is the client giving up before authentication, a 1045 is the server rejecting a completed attempt. Plugin behaviour is documented in the MariaDB Knowledge Base.

  8. Rule out quoting and skip-name-resolve. A password containing $, ! or quotes survives a single-quoted PHP string but is mangled in a double-quoted one, and mangled again on a shell command line. Test credentials through a defaults file rather than an argument, so nothing is re-interpreted and nothing lands in ps:

    umask 077; printf '[client]\nuser=cpuser_wp\npassword=REPLACE_WITH_A_REAL_PASSWORD\n' > /tmp/mysql-1045-test.cnf
    mysql --defaults-file=/tmp/mysql-1045-test.cnf -h localhost cpuser_wpdb -e "SELECT DATABASE();"
    rm -f /tmp/mysql-1045-test.cnf
    +-------------+
    | DATABASE()  |
    +-------------+
    | cpuser_wpdb |
    +-------------+

    Separately, if any grant is written against a hostname rather than an IP, check whether the server resolves names at all:

    mysql -e "SHOW VARIABLES LIKE 'skip_name_resolve';"
    +-------------------+-------+
    | Variable_name     | Value |
    +-------------------+-------+
    | skip_name_resolve | ON    |
    +-------------------+-------+

    With ON, MySQL never resolves the client’s address, so a grant for 'app'@'web1.example.com' can never match and every connection from that host gets 1045. Rewrite those grants against the IP address rather than turning the setting off.

Validate it works

Connect exactly as the application does — same user, same host string, same database — and ask MySQL which account it decided you are:

mysql -u cpuser_wp -p -h localhost cpuser_wpdb -e "SELECT DATABASE(), USER(), CURRENT_USER();"
+-------------+---------------------+---------------------+
| DATABASE()  | USER()              | CURRENT_USER()      |
+-------------+---------------------+---------------------+
| cpuser_wpdb | cpuser_wp@localhost | cpuser_wp@localhost |
+-------------+---------------------+---------------------+

USER() is what the client asked for; CURRENT_USER() is the row MySQL matched. When they differ — USER() showing a real hostname while CURRENT_USER() shows cpuser_wp@% — you matched a wildcard row, which works today and breaks the next time a more specific row appears.

Then confirm the application agrees, from PHP’s side:

wp db check --path=/home/cpuser/public_html
cpuser_wpdb.wp_options                             OK
cpuser_wpdb.wp_posts                               OK
Success: Database checked.

Finally check the site itself — a fixed database connection is not the same thing as a working page:

curl -s -o /dev/null -w '%{http_code}\n' https://example.com/
200

Troubleshooting

  • It works as root but the application still fails. Connecting as root proves the server is up and nothing more: root matches a different row, and on MariaDB may be authenticating by socket rather than by password. Re-test with the application’s own user, host, and database before declaring the 1045 fixed.
  • The reset worked in mysql but WordPress still shows access denied. Look for a second copy of the credentials: a wp-config.php above the document root, an object-cache drop-in with its own connection, or a cron job still carrying the old password. PHP’s opcache can also be holding the old wp-config.php; a PHP-FPM reload for that account settles it.
  • The password contains $ and the config is double-quoted. In PHP, a $ inside a double-quoted string starts interpolation, so the password reaching MySQL is not the password in the file. WordPress writes define( 'DB_PASSWORD', '...' ) with single quotes for exactly this reason. Restore single quotes, or pick a password without $.
  • 1045 appeared right after a restore or an account transfer. A restore can recreate the database and tables without recreating the user, or recreate the user with the source server’s prefix when the cPanel username differs on the destination. Run step 3 on the new server and compare the prefix character by character before assuming the password is wrong.
  • The failure is intermittent — most connections work, some get 1045. Two rows for the same username with different passwords is the usual cause: a specific host row and a % row. Which one matches depends on how the client connected, and on whether reverse DNS answered. Run SELECT user, host FROM mysql.user WHERE user = 'cpuser_wp'; and align or remove the duplicate.

When this is the wrong approach

If the error number is not 1045, this page is not your page. ERROR 2002 and ERROR 2003 mean nothing accepted the connection at all — the server is down, the socket path is wrong, or a firewall dropped the packet — and are covered in can’t connect to local MySQL server through socket. ERROR 1044 is a privilege problem after a successful login, and ERROR 1040 means the connection limit is full.

Resist the reflex of granting 'user'@'%' to make a 1045 disappear. It works, and it leaves an account any host on the network can attempt to authenticate against. Fix the host value in the config instead. Nor should you reset MySQL root by hand on a cPanel server: the cPanel daemons read root’s credentials from /root/.my.cnf, and a reset that misses that file breaks backups, account creation, and the MySQL area of the interface at once.

And if every account on the box started failing at the same moment, stop working account by account. That pattern points at the mysql system schema itself — a partial restore, an interrupted upgrade, an inconsistent grant table — and needs a server-level recovery, not password resets.

If this is the kind of work you’d rather never own again, it’s the daily job of Managed Cloud Ops — book an infrastructure review.