"Access denied for user" is MySQL's way of saying the login didn't match: wrong name, wrong password, no permission on that database, or a connection from somewhere it doesn't expect. This guide explains how to read the error, then walks through each cause we see on cPanel hosting -- the username_ prefix, a user that was never added to the database, the wrong host, and mismatched wp-config.php settings -- and how to fix it.
How to read the error message
The message tells you more than it seems. Here's a typical one:
ERROR 1045 (28000): Access denied for user 'shopuser'@'localhost' (using password: YES)
1045-- the login itself failed (name or password).'shopuser'-- the username MySQL actually received. Compare it character by character with what's in cPanel.'localhost'-- where MySQL thinks the connection came from.using password: YES-- a password was sent (but was wrong).NOmeans no password was sent at all -- the password setting is empty or wasn't read.
The other codes you'll see:
| Error | What it means |
|---|---|
1045 Access denied for user ... (using password: YES/NO) | Username doesn't exist or the password is wrong. |
1044 Access denied for user ... to database '...' | The login worked, but that user has no permission on that database. |
1049 Unknown database '...' | No database with that exact name exists. |
1142 ... command denied to user | The user is logged in but isn't allowed to do that particular thing (for example, it only has read-only privileges). |
2002 Can't connect to ... server / 2005 Unknown ... server host | The connection never reached MySQL -- usually a wrong host setting. |
In WordPress, all of these usually show up as the same page: Error establishing a database connection. The steps below fix them too.
Cause 1: The username or database name is missing the prefix
On cPanel, every database and database user is automatically named with your cPanel username and an underscore in front. If you typed shopuser when you created the user, its real name is username_shopuser. The short name doesn't exist, so MySQL says access denied.
This happens most after moving a site from another host, or when following a script's install instructions that assume you picked the name freely.
How to fix it
- Log in to cPanel and go to Databases > Manage My Databases.
- Copy the full names from the Current Databases and Current Users tables.
- Paste them into your website's config file, replacing the short names.
Cause 2: The user was never added to the database
Creating a database and creating a user are two separate steps. Until you link them, the user can log in to MySQL but can't touch the database -- that's error 1044, or a 1045 in some apps.
How to check and fix it
- In Manage My Databases, find the database under Current Databases.
- Look at the Privileged Users column. If your user isn't listed, it isn't linked.
- Scroll to Add User To Database, choose the user and the database, and click Add.
- Tick ALL PRIVILEGES and click Make Changes.
If the user is listed but you still get 1142 command denied, it may have been given only some privileges. Click the username in the Privileged Users column, tick ALL PRIVILEGES and click Make Changes.
Cause 3: The password doesn't match
This is the single most common cause. Someone changed the database user's password in cPanel, or the site was copied from somewhere else, and the config file still has the old one. cPanel can't show you the current password, so the fix is to set a new one and put it in both places.
- In Manage My Databases, scroll to Current Users and click Change Password next to the user.
- Click Password Generator (or type a strong password), copy it, and click Change Password.
- Paste the same password into your website's config file straight away (see below).
Tip: stick to letters and numbers in database passwords, and make them long instead of adding symbols. Quote marks, backslashes and dollar signs can break config files, which then send a different password from the one you think.
Cause 4: The wrong host
Your website and its database run on the same server, so the host should always be:
localhost
Problems come from settings like your domain name, the server's IP address, mysql.example.com or a host name copied from your old provider. Those either fail to connect (2002/2005) or arrive at MySQL looking like a connection from a different place, which the database user isn't set up for, so you get Access denied for user 'username_shopuser'@'some-other-host'. If the part after the @ in the error isn't localhost, check your host setting.
The one exception is a desktop app connecting through an SSH tunnel, where the MySQL host is 127.0.0.1 -- see the SSH tunnel guide in the related links. Remote MySQL (connecting straight from another computer or service) isn't offered on our hosting.
Cause 5: WordPress wp-config.php settings
For WordPress, the four database settings live in wp-config.php:
- In cPanel, go to Files > File Manager and open the folder WordPress is in (usually
public_html). - Right-click
wp-config.phpand choose Edit. - Check that the lines look like this, with your own values:
define( 'DB_NAME', 'username_wp482' ); define( 'DB_USER', 'username_wpuser' ); define( 'DB_PASSWORD', 'PasteTheNewPasswordHere' ); define( 'DB_HOST', 'localhost' ); - Click Save Changes and reload your site.
Things to watch for while you're in there:
- Straight quotes only. If you pasted from a word processor or email, curly quotes (‘ ’) break the line. Retype them.
- No extra spaces inside the quote marks, before or after the value.
- Only one set of each line. Some sites have a second
define( 'DB_PASSWORD', ...further down, which overrides the first. - The right file. If you have a staging copy or an old folder, make sure you're editing the
wp-config.phpof the site that shows the error.
Other software uses the same four values in its own file -- configuration.php for Joomla ($host, $user, $password, $db), .env for Laravel (DB_HOST, DB_DATABASE, DB_USERNAME, DB_PASSWORD).
Test the login yourself
To prove whether the problem is the login or the website, test the details directly. Open Advanced > Terminal in cPanel and run:
mysql -u username_wpuser -p username_wp482 -e "SELECT 1;"
Paste the password when asked. A small table with 1 in it means the name, password and permissions are all correct -- so if the site still fails, the config file isn't saying what you think. An Access denied error here means the problem is in cPanel, and the causes above apply.
WordPress users can also run wp db check from the site's folder, which uses the details in wp-config.php exactly as the site does.
Troubleshooting
It worked yesterday and nothing changed
Something usually did: a password reset, a restore, a migration plugin, or a security plugin that "hardened" wp-config.php. If the site was hacked, the attacker may have changed the file. Check the file's modified date in File Manager, and see our hacked-site guide if anything looks unfamiliar.
phpMyAdmin says access denied
Open phpMyAdmin from cPanel (Databases > phpMyAdmin) rather than a bookmark -- it logs you in automatically. If it still shows an access error, open a ticket with a screenshot.
Access denied for user 'username'@'localhost' -- my cPanel username, not a database user
The script is using your cPanel username instead of a database user, often because the database user setting is blank or misspelled. Create a proper database user, add it to the database, and put that name in the config file.
The error comes and goes
A login problem is constant. If the site works sometimes and fails at busy times, look at resource limits instead (Metrics > Resource Usage) -- see the related guides.
Common questions
Can I see the current database password in cPanel?
No. cPanel stores it scrambled. The password your site uses is in its config file; if you need a new one, set it with Change Password and update the file.
Is the database password the same as my cPanel password?
No. Database users have their own passwords. Changing your cPanel password doesn't affect them.
How many failed attempts before I'm locked out?
Database logins from your website aren't the same as logging in to cPanel, but repeated failed logins to cPanel, email or SSH can get your IP address blocked by the firewall. If you suddenly can't reach anything, open a ticket with your IP address.
Related guides
- How to Fix "Error Establishing a Database Connection" in WordPress
- How to Change a MySQL Database User's Password
- How to Create a MySQL Database and User in cPanel
- How to Edit a File in cPanel File Manager
- What to Do If Your WordPress Site Is Hacked
- cPanel Resource Usage Explained: CPU, Memory and Entry Process Limits
Still stuck? Open a support ticket and the Instant Access Internet Services team will help.
