Error establishing a database connection or access denied
On this page
Symptoms
- WordPress shows "Error establishing a database connection".
- An application or log shows
SQLSTATE[HY000] [1045] Access denied for user 'username_shop'@'localhost' (using password: YES). Unknown databaseor#1044 - Access denied for user … to database ….- A desktop tool cannot connect from your computer.
Causes
- The name is missing the prefix. Databases and users are always called
username_something. - The password in the configuration file is wrong (or was changed in the panel).
- The user is not added to the database.
- The host is not
localhost. - From another computer: the address is not allowed in Remote MySQL.
- The database was deleted or a table is damaged.
Fix
1. Use the full names
Open MySQL Databases (section Databases). Copy the exact database name from Databases and the user name from Database users into your configuration file (for WordPress, DB_NAME and DB_USER in wp-config.php).
2. Set the password again
Under Database users, click Password next to the user, enter a new password and click Change. Put the same password in the configuration file. See how to change a database password.
3. Add the user to the database
Look under Privileged users next to the database. If the user is not there, use Add user to database → Grant all privileges. See privileges.
4. Use localhost as host
Set the host to localhost (WordPress: DB_HOST). Do not use 127.0.0.1, the server's IP address or the domain for websites on this server. See connection details.
5. Allow your address for remote connections
For a desktop tool or another server, add its public address in Remote MySQL and connect to the server name shown there, port 3306. See Remote MySQL.
6. Check the database itself
Make sure the database still exists in the list. If the error mentions a crashed or damaged table, run Check & repair.
Still not working?
- Wait a minute after any change: new users, passwords and privileges are applied within seconds, remote addresses within a minute.
- Open phpMyAdmin from MySQL Databases: if your tables are there, the database is fine and the problem is in the configuration file.
- Check that the account has disk space left on Resource Usage; a full disk can stop the database from writing.
- Run Site Check for the website and contact support with its result and the exact error message.
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
- MySQL connection details: host, port, socket and examples
The database host (localhost), port 3306, socket path, name and user format to connect WordPress, PHP, Laravel, Node.js or Python to MySQL, with examples.
- How to change a MySQL or PostgreSQL database user password
Set a new password for a database user in MySQL Databases or PostgreSQL Databases, then update wp-config.php or your app's settings so the site keeps working.
- How to add a user to a MySQL database (privileges)
Give a database user access to a MySQL database with Grant all privileges, remove its access again, and understand which privileges the user gets.
- How to check and repair a crashed MySQL table
Fix "Table is marked as crashed and should be repaired" with Check & repair in MySQL Databases, read the result, and what to do when a table cannot be repaired.