How to Move WordPress to a New Hosting Provider
Recent Posts
Digital Marketing Trends 2026: What Indian Businesses Must Know
Retargeting Ads Explained: How to Bring Back Lost Visitors (2026)
Marketing Funnel 2026: How Indian Customers Actually Buy Now
Performance Marketing Explained: CPL, ROAS, CAC for Indian Businesses
There are few WordPress errors more alarming than this one:
Your entire website goes blank. No homepage, no admin dashboard, nothing. Just that single, ominous line — and no hint of where to start fixing it.
The WordPress database is the heart of your website. Every post, page, comment, setting, and user account lives in the database. When WordPress can't connect to it, the entire site stops functioning.
The good news: this error is almost always caused by one of a small handful of problems — and every single one of them is fixable without losing your content. In this complete guide, we'll walk through every cause and every solution, step by step.
What Is a WordPress Database Connection Error?
WordPress is a dynamic CMS — it doesn't serve static HTML files. Every time someone visits your site, WordPress connects to a MySQL (or MariaDB) database, queries it for the right content, and assembles the page on the fly.
If that connection fails at any point, WordPress can't render anything and displays the "Error Establishing a Database Connection" message instead.
This error can manifest in several ways:
- The front end of your site shows "Error Establishing a Database Connection"
- Your wp-admin shows "One or more database tables are unavailable. The database may need to be repaired."
- Only your homepage loads but all other pages show the error
- The error appears and disappears intermittently
Each variation points to a slightly different root cause — which we'll cover below.
What Causes a WordPress Database Connection Error?
- Wrong database credentials in wp-config.php — The most common cause by far. If the database name, username, password, or host in your
wp-config.phpfile doesn't match what your hosting provider has configured, WordPress can't connect. - Corrupted WordPress database — Database tables can become corrupted due to a server crash, a failed update, or a sudden loss of power during a write operation. Corrupted tables prevent WordPress from reading or writing data correctly.
- Database server is down — Your MySQL or MariaDB server may have crashed or been temporarily shut down by your hosting provider for maintenance.
- Incorrect database host — Most shared hosting uses
localhostas the database host, but some hosts use a specific IP address or hostname. Using the wrong value will prevent connection. - Database user lacks permissions — Even if your credentials are correct, the database user may not have been granted the necessary privileges to access the database.
- Exhausted database connections — On shared hosting plans, there's a limit on the number of simultaneous database connections. During a traffic spike, you can hit this ceiling and start seeing connection errors.
- Corrupted wp-config.php file — If
wp-config.phpitself has a syntax error or was accidentally edited, WordPress may fail to read the credentials from it. - Malware or hack — A compromised site may have had its
wp-config.phpcredentials changed by an attacker.
How to Resolve a WordPress Database Connection Error
Start here — this resolves the majority of database connection errors. Your wp-config.php file stores the four credentials WordPress uses to connect to the database:
- Database name
- Database username
- Database password
- Database host
If any one of these is wrong, the connection fails immediately.
Step 1: Open wp-config.php
Connect to your server via FTP or your hosting file manager and navigate to your WordPress root directory. Open the file named wp-config.php.
Look for these four lines:
define( 'DB_NAME', 'your_database_name' );
define( 'DB_USER', 'your_database_username' );
define( 'DB_PASSWORD', 'your_database_password' );
define( 'DB_HOST', 'localhost' );
Step 2: Verify the credentials against your hosting account
Now log in to your hosting control panel (cPanel, Plesk, etc.) and find the database section — usually called MySQL Databases or Database Manager.
Cross-check every value:
- DB_NAME — Must exactly match the name of your database as shown in your hosting panel
- DB_USER — Must exactly match the database username that has been assigned to that database
- DB_PASSWORD — Must match the password for that database user (passwords are case-sensitive)
- DB_HOST — Usually
localhoston shared hosting. Some hosts use127.0.0.1or a custom hostname likemysql.yourdomain.com
Step 3: Update any incorrect values
If any credential doesn't match, correct it in wp-config.php, save the file, and reload your site. This single step fixes the database connection error in a large percentage of cases.
MyDatabase and mydatabase are different. Double-check capitalization carefully.Even if your credentials are correct, the database or user may have been accidentally deleted, or the user may not have been properly assigned to the database.
In cPanel:
- Log in to cPanel and go to MySQL Databases
- Scroll down to the Current Databases section and confirm your database is listed
- Scroll further to Current Users and confirm your database user exists
- Check the Add User to Database section and confirm the user is linked to the database with All Privileges
If the user is not linked to the database:
- Select the user and database from the dropdowns in "Add User to Database"
- Click Add
- On the next screen, select All Privileges and click Make Changes
Reload your site and test.
Sometimes the issue isn't your credentials — it's that the MySQL server itself has crashed or stopped running.
Signs that this is the cause:
- The error appeared suddenly without any changes on your end
- The error is intermittent (comes and goes)
- Multiple websites on the same server are experiencing issues
What to do:
- Log in to your hosting control panel and check the server status panel if one is available
- Check if your host has posted any service announcements or outage notices
- Contact your hosting provider's support team and ask them to confirm whether the MySQL server is running
On a VPS or dedicated server where you have root access, you can check and restart MySQL yourself:
# Check MySQL status
sudo systemctl status mysql
# Restart MySQL if it's stopped
sudo systemctl restart mysql
# For MariaDB
sudo systemctl restart mariadb
If your credentials are definitely correct but the connection still fails, the database host value may be wrong. localhost works for most shared hosting, but not always.
Try replacing localhost in your wp-config.php with each of the following, saving and testing after each:
define( 'DB_HOST', '127.0.0.1' );
define( 'DB_HOST', 'localhost:3306' );
If you're on a specific managed host, check their documentation for the correct database host value. For example:
- WP Engine uses a custom hostname like
yoursitename.mysql.wpengine.com - Kinsta uses a custom internal hostname
- GoDaddy shared hosting sometimes requires a specific hostname found in cPanel
If your credentials are correct but WordPress still can't operate properly — or if your wp-admin shows a message about unavailable database tables — your database may be corrupted.
WordPress has a built-in database repair tool that you can activate with a single line in wp-config.php.
Step 1: Enable the repair tool
Open wp-config.php and add this line just before the /* That's all, stop editing! */ comment:
define( 'WP_ALLOW_REPAIR', true );
Save the file.
Step 2: Run the repair tool
Open your browser and navigate to:
https://yourdomain.com/wp-admin/maint/repair.php
Replace yourdomain.com with your actual domain.
You'll see a page with two options:
- Repair Database — Fixes corrupted tables
- Repair and Optimize Database — Fixes and optimizes all tables for better performance
Click Repair Database first. WordPress will scan all tables and attempt to repair any that are corrupted.
Step 3: Disable the repair tool
This is important. Once the repair is complete, remove the line you added from wp-config.php immediately:
define( 'WP_ALLOW_REPAIR', true ); // Remove this line
The repair page is publicly accessible — anyone can visit it. Leaving it enabled is a security risk.
Step 4: Repair via phpMyAdmin if the built-in tool doesn't work
- Log in to your hosting control panel and open phpMyAdmin
- Select your WordPress database from the left sidebar
- Click Check All to select all tables
- In the "With selected" dropdown at the bottom, choose Repair table
- Click Go
phpMyAdmin will attempt to repair each table and report the results.
A single typo in wp-config.php — a missing quote, an extra space, or an accidental character — can prevent WordPress from reading the file entirely, causing a database connection error.
Common mistakes to look for:
Wrong (missing closing quote):
define( 'DB_NAME', 'my_database );
Correct:
define( 'DB_NAME', 'my_database' );
Wrong (extra space in password):
define( 'DB_PASSWORD', 'mypassword ' );
Correct:
define( 'DB_PASSWORD', 'mypassword' );
Also make sure there is no whitespace or blank lines before the opening <?php tag at the very top of the file. Any character before <?php can break PHP's ability to parse the file.
If you're not sure whether the file is correct, you can download a fresh copy of wp-config-sample.php from the WordPress repository on GitHub, use it as a template, and carefully re-enter your credentials.
On shared hosting plans, your account is allocated a maximum number of simultaneous database connections — typically between 10 and 25. During a traffic spike or if a plugin is opening connections inefficiently, you can hit this limit and start seeing connection errors for some visitors.
Signs this is the cause:
- The error is intermittent — it appears and disappears on its own
- It happens more during busy periods
- Your server resource usage in cPanel shows high MySQL usage
How to fix it:
- Install a database optimization plugin like WP-Optimize or WP-DBManager to clean up unnecessary data and post revisions that may be causing excessive queries
- Enable a caching plugin like W3 Total Cache or WP Super Cache to reduce the number of database queries per page load
- Contact your hosting provider and ask about increasing your database connection limit, or consider upgrading to a VPS plan that offers greater resources
If you've tried every fix above and nothing has worked — or if your database is so corrupted that the repair tool can't help — restoring from a clean backup is the most reliable path to recovery.
How to restore a WordPress backup:
If you use UpdraftPlus:
- Go to Settings → UpdraftPlus Backups in wp-admin (you may need to access this via a temporary recovery URL)
- Find the most recent backup before the error appeared
- Click Restore and select the Database component
If you use your hosting provider's backup system:
- Log in to cPanel or your hosting panel
- Find the Backup or Backup Wizard section
- Restore the most recent MySQL database backup
After restoring, update your wp-config.php to confirm all credentials still match, then reload your site.
If your database connection error appeared suddenly and without any changes on your part, a malware infection may have modified your wp-config.php file, changed your database credentials, or corrupted your database tables.
Steps to check for malware:
- Install and run Wordfence Security (free version available) — it will scan all files including
wp-config.phpfor unauthorized changes - Check
wp-config.phpmanually via FTP and look for any credentials that don't match what's in your hosting panel — a clear sign of tampering - Contact your hosting provider — most managed hosts offer malware scanning and will alert you if malicious activity is detected on your account
If malware is confirmed, follow a full WordPress malware removal process, change all passwords (WordPress admin, database, FTP, hosting panel), and consider engaging a professional security service.
If you've worked through every fix in this guide and the database connection error persists, it's time to contact your hosting provider. Provide them with:
- The exact error message you're seeing
- When the error started
- What changes (if any) preceded the error
- The steps you've already tried
Good hosting providers can check:
- Whether the MySQL server is running and accepting connections
- Whether your database account is intact and has correct privileges
- Server-side error logs showing what MySQL is reporting
- Whether there's a known issue or maintenance affecting your server
Preventing the WordPress Database Connection Error
- Take regular backups. A reliable backup is your ultimate safety net. Use UpdraftPlus, BlogVault, or your host's built-in backup system to back up your database daily. Store backups in a remote location like Google Drive or Dropbox.
- Use a managed WordPress host. Managed hosts like Kinsta, WP Engine, and Cloudways actively monitor your database and server health, alerting you to problems before they cause downtime.
- Protect wp-config.php. Add the following to your
.htaccessfile to prevent unauthorized access to your database credentials file:
<files wp-config.php>
order allow,deny
deny from all
</files>
- Keep a record of your database credentials. Store your database name, username, and password securely (in a password manager). You'll need them if you ever have to rebuild or recover your site.
- Optimize your database regularly. Use WP-Optimize or a similar plugin to clean up post revisions, spam comments, transient data, and orphaned metadata. A leaner database is less prone to corruption and connection overload.
- Monitor your site's uptime. Use a free uptime monitor like UptimeRobot to get instant alerts the moment your site goes down — so you can start troubleshooting before your visitors even notice.
Quick Reference: Database Connection Error Fix Summary
| Cause | Fix |
|---|---|
| Wrong database credentials | Check and correct DB_NAME, DB_USER, DB_PASSWORD, DB_HOST in wp-config.php |
| User not assigned to database | Add user to database with All Privileges in cPanel |
| MySQL server is down | Contact host or restart MySQL on VPS |
| Wrong database host value | Try 127.0.0.1 or check host-specific documentation |
| Corrupted database tables | Use WordPress built-in repair tool or phpMyAdmin |
| Syntax error in wp-config.php | Check file for typos, missing quotes, or whitespace before <?php |
| Connection limit exceeded | Enable caching, optimize queries, or upgrade hosting plan |
| Malware attack | Run security scan, check credentials, change all passwords |
| Nothing works | Restore from a clean backup |
Frequently Asked Questions
Q: Will fixing the database connection error delete my content?
Q: How do I find my WordPress database credentials?
wp-config.php with the new one.
Q: Why does the database connection error appear intermittently?
Q: Is "Error Establishing a Database Connection" the same as a hacked site?
Q: Can I fix this error without FTP access?
wp-config.php there without FTP. For everything else, a file manager or FTP client is the most reliable approach.
Final Thoughts
The WordPress database connection error is scary — but it's rarely a sign of catastrophic data loss. In most cases, it comes down to a credential mismatch in wp-config.php or a temporarily unavailable MySQL server, both of which can be fixed in just a few minutes.
Work through the fixes in this guide from top to bottom. Start with your credentials, check whether your database server is running, repair any corrupted tables, and use debug tools to identify anything unusual. In the vast majority of cases, you'll have your site back online well before reaching the bottom of this list.
If the problem keeps coming back, or if you suspect a security breach, it's time to bring in a professional. Our WordPress development team has resolved database connection issues across hundreds of websites — from simple credential fixes to full malware recoveries.
Contact us today and we'll get your database — and your website — back online fast.