Few errors stop a website owner in their tracks faster than “Error establishing a database connection.” Because WordPress stores every post, page, user, and plugin setting inside a MySQL database, this error completely blocks both your front-end visitors and your /wp-admin/ dashboard.
The good news? Your content is almost certainly safe. Follow this 4-step checklist to identify the exact cause and bring your WordPress site back online.
1. Check If Your Entire Hosting Server Is Overloaded
On free hosting and entry-level shared hosting, the MySQL server is the first service to refuse connections when your account hits its memory or concurrent connection ceiling.
- First, test your domain in our Website Host & IP Checker to verify your DNS and server are reachable.
- Log into cPanel and check Resource Usage. If your site frequently hits MySQL connection limits, calculate your true server needs with our WordPress Hosting Requirement Calculator.
2. Verify `wp-config.php` Database Credentials
If you recently migrated your site, changed a cPanel password, or restored a backup, your wp-config.php credentials may be out of sync:
define( 'DB_NAME', 'your_database_name' );
define( 'DB_USER', 'your_database_user' );
define( 'DB_PASSWORD', 'your_strong_password' );
define( 'DB_HOST', 'localhost' );Open MySQL Databases in cPanel, verify that the database user is assigned to the database with ALL PRIVILEGES, and update the password if needed. (Need a strong, unguessable database password? Generate one in our Free Cryptographic Password Generator.)
3. Repair Corrupted WordPress Database Tables via phpMyAdmin
If your server shut down abruptly during a write operation, a table like wp_options or wp_posts may be marked as crashed:
- Open phpMyAdmin inside your hosting control panel.
- Select your WordPress database on the left sidebar.
- Scroll to the bottom, click Check all, and choose Repair table from the dropdown menu.
4. Prevent Future Database Crashes
Once your site is back online, install a page caching plugin so repeat visitors are served static HTML instead of triggering 50+ MySQL queries on every page load—and check our Hosting Upgrade Decision Tool if your traffic has outgrown your current plan.
Frequently Asked Questions (FAQ)
Why does WordPress say Error Establishing a Database Connection?
WordPress cannot communicate with your MySQL or MariaDB database because either the login credentials in wp-config.php are wrong, the database table is corrupted, or your hosting server’s MySQL process crashed due to resource limits.
Where do I check my WordPress database username and password?
Open cPanel File Manager, navigate to your public_html folder, and inspect the DB_NAME, DB_USER, DB_PASSWORD, and DB_HOST lines inside wp-config.php.
Can traffic spikes cause a database connection error on shared hosting?
Yes. Shared and free hosting plans cap concurrent MySQL connections (often 15 to 25 at a time). When traffic or bot crawls exceed that cap, new visitors see a database connection error.