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.
Open the database from your project's Overview.
Under Apps with its connection details, switch on your app.
The app redeploys with the right
DB_USERNAME,DB_PASSWORDandDATABASE_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
.envfrom cPanel had a user likeasha_shopand its password. Those don't exist here. An own database's main user isdb_and the project's name, likedb_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
Open the project's Variables tab.
DB_USERNAMEandDB_PASSWORDshould show as added by the database. If you see them as set by you, the database isn't attached to this app.Compare the user in the error,
Access denied for user 'db_duka'@…, with the User in the database's Connect section.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:
php artisan db:showIf 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.