MySQL error 1045 "Access denied for user 'name'@'host' (using password: YES)" means the database server rejected the login. Either the username does not exist for that host, the password is wrong, or the user has no rights on the database. On cPanel it often appears after moving a site, because names and passwords in the config file no longer match.
Before you start
- Open the application's config file (for WordPress,
wp-config.php) and noteDB_NAME,DB_USER,DB_PASSWORDandDB_HOST. - Open cPanel → Databases → MySQL Databases.
Read the error carefully
- using password: NO – the app sent no password; the config value is empty or not read.
- 'user'@'localhost' – the user and host MySQL saw. Make sure that is the user you expected.
Fix it in cPanel
- Check the full names. cPanel prefixes databases and users with your account name, e.g.
cpuser_wp. The config must use the full prefixed names. - Reset the password. Under Current Users, click Change Password for the user, set a new one and copy it exactly into the config file.
- Add the user to the database. Under Add User to Database, choose the user and database, then grant ALL PRIVILEGES.
- Use
localhostas host for apps on the same account. - For remote connections, add your IP in Databases → Remote MySQL and connect to the server hostname.
Fix it on a VPS
- Log in as root:
mysql -u root -p(orsudo mysql). - Check users:
SELECT user, host FROM mysql.user; - Reset the password and grant rights:
ALTER USER 'appuser'@'localhost' IDENTIFIED BY 'NewStrongPass!'; GRANT ALL PRIVILEGES ON appdb.* TO 'appuser'@'localhost'; FLUSH PRIVILEGES; - If root itself is denied, follow reset the MySQL root password.
Tip: Special characters such as $ or quotes in a password can break config files. If you set one, check it is quoted correctly, or pick a long password without them.
FAQ
Why did it work before the migration?
The new account has a different prefix or password. Update the config file to match.
Is 'localhost' different from 127.0.0.1?
To MySQL, yes: localhost uses a socket, 127.0.0.1 uses TCP, and users can be defined for one but not the other.
Does this cause "Error establishing a database connection"?
Yes, on WordPress that message often hides a 1045 error.
