Skip to content
Docs

SQLSTATE[HY000] [1045] Access denied for user

Let the database fill in its own user and password. On Tanzahost you never copy a database password by hand, so it can't be wrong or out of date.

Updated 17 Oct 20262 min read

The fix on Tanzahost: attach the database to your app, so its user and password come from the database itself. Don't type DB_USERNAME or DB_PASSWORD.

  1. Open the database from your project's Overview.

  2. Under Apps with its connection details, switch on your app.

  3. The app redeploys with the right DB_USERNAME, DB_PASSWORD and DATABASE_URL, without downtime.

When you change the database's password later, every attached app gets the new one and restarts by itself. See Connect an app to a database.

Why it happens

Error 1045 means the database answered, but refused the user name or the password. On Tanzahost the usual reasons are:

  • An old host's details. Your .env from cPanel had a user like asha_shop and its password. Those don't exist here. An own database's main user is db_ and the project's name, like db_duka.

  • A password copied by hand. It was typed into a variable or a config file, and the database's password changed since.

  • An extra user, made under Users on the database's page, with its password copied wrong. Copy it again with its copy button.

  • A password being changed. For MySQL the old password keeps working until every attached app runs with the new one. PostgreSQL, MariaDB and Valkey have no second password, so for the few seconds until the apps restart, a new connection with the old one is refused. It clears up by itself.

How to check

  1. Open the project's Variables tab. DB_USERNAME and DB_PASSWORD should show as added by the database. If you see them as set by you, the database isn't attached to this app.

  2. Compare the user in the error, Access denied for user 'db_duka'@…, with the User in the database's Connect section.

  3. For Laravel, try the same login from the app's terminal. It connects with the app's own variables and shows the database it reached:

Terminal
php artisan db:show

If that works and your app still fails, your code reads its login from somewhere else, like a file in your repository. Make it read the variables.