The page shows one white line saying «Error establishing a database connection» and nothing else. It is not a WordPress fault: it is WordPress telling you it asked the database for the data and got nothing back. There are only a few causes, and they have an order of likelihood that rarely lets you down.
|
Before editing wp-config.php, keep a copy of it. It is the file holding the database password. Download it to your computer, or copy it outside public_html. Never leave a copy called wp-config.bak or wp-config.txt inside the site folder: a file with those extensions is served as plain text to anyone who guesses the name, and the password becomes public.
|
First: is it only this site?
Thirty seconds that save half an hour. Answer these three:
| 1 |
Does /wp-admin give the same error? If it does, it is the database and not the site. If the dashboard opens, the problem is something else.
|
|
| 2 |
Do you have another site on the same account? If the other one opens, the database service is up and the problem belongs to this installation.
|
|
| 3 |
Does phpMyAdmin open from cPanel? If it does and you can see the database with all its tables, then the database exists and what is failing is the authorisation. See databases and phpMyAdmin.
|
|
The causes, in order
| Cause |
How to recognise it and how to fix it |
| 1. Wrong password |
The commonest, by far. Somebody changed the database user’s password in cPanel and did not correct it in wp-config.php. It also happens every time a site is copied from another server. |
| 2. User not attached to the database |
The user exists, the database exists, but they are not linked. In MySQL Databases, under Add User To Database, join the two and give ALL PRIVILEGES. |
| 3. Wrong database name |
On a shared account the real name carries the account prefix: it is not wordpress, it is account_wordpress. Same for the username. Anyone bringing a site in from outside forgets this every time. |
| 4. Wrong DB_HOST |
Here it is localhost. If the file came from another provider, it may carry an address or a server name that does not exist here. |
| 5. The account hit a limit |
With no disk space, or no file allowance left, the database can no longer write and the connection drops. Look at what cPanel shows and at the limits nobody advertises. |
| 6. A corrupted table |
The error comes and goes, or shows up only on some pages. Dealt with below, with the repair tool. |
| 7. The service is down on our side |
Rare, and recognisable because it hits every site on the account at once, phpMyAdmin included. If that is the case, do not change anything: open a request. |
Checking the four lines
In cPanel, File Manager, site folder, wp-config.php, Edit. Near the top are the four lines that matter:
| 1 |
define( 'DB_NAME', 'account_wordpress' ); the database name, with the account prefix
|
|
| 2 |
define( 'DB_USER', 'account_wpuser' ); the user, also with the prefix
|
|
| 3 |
define( 'DB_PASSWORD', '...' ); that user’s password
|
|
| 4 |
define( 'DB_HOST', 'localhost' ); here it is always this
|
|
|
Do not guess the password: set a new one. It is quicker and leaves no doubt. In MySQL Databases, in the user list, choose Change password, generate a new one (password generator), save, and put exactly that into wp-config.php. Watch for stray spaces at either end when you paste.
|
|
Quotes and apostrophes. If the password contains an apostrophe, a backslash or a dollar sign, it breaks the PHP line and the error stays, now for a different reason. The safe route is to generate a long password using only letters and digits, rather than fighting with escaping.
|
If the credentials are right: repairing the tables
WordPress ships a repair tool that does not need a login. You turn it on, use it, and turn it off:
| 1 |
Add define( 'WP_ALLOW_REPAIR', true ); to wp-config.php.
|
|
| 2 |
Open https://yourcompany.com/wp-admin/maint/repair.php and choose repair, or repair and optimise.
|
|
| 3 |
Remove the line afterwards. While it is there, that page is open to everybody, with no password at all.
|
|
If you would rather do it by hand, phpMyAdmin has the same: select all the tables and choose Repair table from the list at the bottom.
When the error comes and goes
An intermittent error that shows up at busy hours and clears by itself is rarely a wrong password: a wrong password fails every time. That is the account hitting a limit, usually the number of simultaneous requests. Look at Resource Usage in cPanel for the hour it happens: monitoring your site performance in cPanel and the limits nobody advertises.
The underlying cause is usually a heavy site taking too long on each request. Then the article is a different one: the site is slow.
If none of this fixes it
Look at the error_log in the site folder, because for this fault it usually holds a line with the exact reason for the refusal: where the PHP error log is. If the configuration file is damaged or missing, rebuild it: rebuilding the wp-config.php connection. If you do not know which database is yours, find it first. And if the database really was damaged, restore a copy from a day it worked: how to restore your data.
|
Send us the domain, the time it started, and the line from error_log.
Open a request
|
RECOMMENDED PRODUCT Web hosting with cPanel Domain and SSL included, daily backups and the panel you already know. from £8.00/mo See plans |