Skip to content
Databases2 min read

Fix MySQL error 1045: Access denied for user

ERROR 1045 (28000): Access denied for user 'user'@'localhost' (using password: YES)

Short answer

Error 1045 means MySQL refused the login because the username, password or host doesn't match a registered user. On cPanel, use the full prefixed name such as cpuser_shop and the host localhost, then reset the password and update it in your site's config.

ArabyHost teamLast updated: ShareWhatsAppXLinkedIn
Contents
  1. Reading the message
  2. Causes
  3. How to fix it
  4. On your own server
  5. Prevention
  6. On ArabyHost

MySQL turned the connection away at the very first step, before your database was even touched. In PHP applications the message usually reads:

SQLSTATE[HY000] [1045] Access denied for user 'cpuser_shop'@'localhost' (using password: YES)

WordPress hides it behind Error establishing a database connection.

Reading the message

  • 'cpuser_shop'@'localhost': the username that reached the server and the host it connected from. Check the name is complete.
  • using password: YES: a password was sent but it’s wrong, or the user doesn’t exist.
  • using password: NO: no password was sent, so the variable is probably empty or not loaded.

Causes

  • Wrong password, or you changed it in cPanel without updating the config.
  • Username without the account prefix: shop instead of cpuser_shop.
  • The user doesn’t exist, for example after a migration where it wasn’t recreated.
  • Wrong host: an external address instead of localhost.
  • A password containing # in .env without quotes, so everything after # is read as a comment.
  • Laravel still using cached config.
  • Trying to log in as root on shared hosting.

How to fix it

  1. Open cPanel → Databases → MySQL Databases and copy the user’s full name from Current Users.
  2. Click Change Password next to it, create a strong one with the password generator, and save it.
  3. Under Add User To Database, pick the user and the database, click Add, tick ALL PRIVILEGES and press Make Changes.
  4. Update your site’s settings. For Laravel, in .env:
DB_HOST=localhost
DB_DATABASE=cpuser_shop
DB_USERNAME=cpuser_shop
DB_PASSWORD="your#strong-password"

For WordPress, in wp-config.php:

define( 'DB_NAME', 'cpuser_shop' );
define( 'DB_USER', 'cpuser_shop' );
define( 'DB_PASSWORD', 'your#strong-password' );
define( 'DB_HOST', 'localhost' );
  1. In Laravel, clear the config cache after every change:
php artisan config:clear
  1. If you have SSH, test the login directly:
mysql -u cpuser_shop -p -h localhost cpuser_shop

If this works but the site doesn’t, the problem is in your config file, not the user.

On your own server

Outside cPanel you create the user and grant privileges in SQL:

CREATE USER 'shop_user'@'localhost' IDENTIFIED BY 'strong-password';
GRANT ALL PRIVILEGES ON shop_db.* TO 'shop_user'@'localhost';
FLUSH PRIVILEGES;

On cPanel, always create users through the interface: cPanel tracks them and adds the prefix for you.

Prevention

  • Store each database’s credentials in a password manager when you create it.
  • When you change a password in cPanel, update the config at the same moment.
  • Quote passwords that contain symbols in .env.

On ArabyHost

Databases run on MariaDB/MySQL with phpMyAdmin, and cPanel opens with one click from the Araby Panel. Database and user names carry your account prefix, like user_dbname, and the host is localhost. The full create-and-connect steps are in the MySQL database guide. If the error persists, ask the Araby AI assistant in the panel; it reads your error log and explains the cause. You can also browse the help center.

FAQ

What's the difference between error 1045 and 1044?

1045 means the login itself failed because of the username, password or host. 1044 means the login worked but the user has no rights on that database; fix it by adding the user to the database.

What does using password: NO mean?

Your app sent no password at all. Check that DB_PASSWORD exists and is being read, and in Laravel clear the config cache with php artisan config:clear.

Can I use the root user on shared hosting?

No. Shared hosting has no root access; you create a dedicated user for each database in cPanel and add it to that database.

Useful? Share it with someone who needs it:WhatsAppXLinkedIn

Read next

Ready to put your idea online?

Fast, isolated hosting, support that understands you, and an AI assistant that fixes problems with you.