Error establishing a database connection (access denied)
On this page
The website cannot sign in to its MySQL database. The database server answers, but the details in the site's configuration file do not match a database and user of your account — very often after a move, where names on this server are different.
Symptoms
- WordPress: Error establishing a database connection.
SQLSTATE[HY000] [1045] Access denied for user 'example_wp'@'localhost' (using password: YES).Unknown database 'example_wp'orSQLSTATE[HY000] [2002] No such file or directory/Connection refused.- A 500 error with one of these lines on the Errors page.
Causes
Most likely first:
- The database or user name lacks your account's prefix, or has another account's prefix after a move.
- The user has no privileges on the database (it was created but never added).
- The password in the configuration file is not the user's password.
- The database host is wrong — it must be
localhost. - Upper and lower case differ in the database name.
- The database does not exist on this server (it was not moved) or a table is damaged.
Fix
Compare the configuration with the panel
- Open MySQL Databases (section Databases). Note the exact database names, the users, and which users are listed under Privileged users of each database.
- Open the site's configuration file in File Manager (section Files) with Edit:
wp-config.phpfor WordPress (DB_NAME,DB_USER,DB_PASSWORD,DB_HOST),configuration.phpfor Joomla,.envfor Laravel,app/etc/env.phpfor Magento, and so on.
1. Name prefix
Every database and database user name starts with your username and an underscore, for example username_wp. Use the full names exactly as shown on MySQL Databases.
2. Privileges
Under Add user to database, choose the user and the database and click Grant all privileges.
3. Password
Next to the user, enter a New password and click Change, then put the same password in the configuration file and save. (The password needs at least 8 characters with 3 of: lowercase, uppercase, digits, symbols.) Watch for quotes: a password containing ' or $ must be written the way the file's language expects.
4. Host
Use localhost as the database host. Database users sign in from this server through localhost; the server's public address or a domain name as host gives "Access denied" or no connection. To connect from another computer, allow its address in Remote MySQL (section Databases).
5. Upper and lower case
Database names are case-sensitive on this server: example_DB and example_db are different databases. Use the name exactly as listed.
6. Missing database or damaged table
- If the database is not listed, it was not moved: create it, then import its
.sqlexport with Open phpMyAdmin (Import). - If the error mentions a crashed or damaged table, click Check & repair next to the database. If a table cannot be repaired, the message names it: restore the database from Backups (section Advanced).
Still not working?
- If all sites of the server fail at once, the database server may be down: tell your host. Administrators check the
mysqlservice (mariadb) in Service Manager; the watchdog restarts it when it stops. - If your host has turned on the AI assistant, click Explain with AI on the Errors page or Fix with the assistant on Site Check.
Thank you — this helps us improve the article.
Still stuck?
Ask the AI about your exact situation — it answers from this knowledge base — or contact us.
Related articles
- Website shows 500 Internal Server Error (HTTP 500)
Find why your website answers "500 Internal Server Error" or a blank page, read the PHP error behind it in the control panel and fix the usual causes.
- WordPress "There has been a critical error" or white screen
Fix the WordPress critical error message or a blank white screen: read the PHP error in the control panel, switch off the broken plugin or theme, or roll back.
- 404 Not Found after moving a website to this server
Pages answer "404 Not Found" after you moved or uploaded a website. Check the website folder, .htaccess rules, file name case and the stored address.