Dec 22, 2025
Aris S. & Ariffud M.
7min Read
“Error establishing a database connection” in WordPress means your website cannot communicate with its MySQL database, preventing the site from loading and showing an error message instead.
This problem usually comes from incorrect database credentials in the configuration file, a corrupted database, or an unresponsive server. To fix it, check your credentials, repair the database, and make sure your server is running correctly.
If you prefer a visual guide to solve “Error establishing a database connection,” check out this video from Hostinger Academy. It covers how to match your database login credentials, verify where your domain is pointing, and fix corrupted files.

“Error establishing a database connection” is a common WordPress issue that occurs when your website’s files (PHP) fail to communicate with its MySQL database.
Your WordPress site runs on the PHP programming language, while all of its content and settings live in a MySQL database.
When a visitor opens your website, PHP code runs a request to fetch the necessary information from the database. The database then returns the data, and WordPress assembles it into a complete web page.
If the PHP code cannot connect to the database, the process stops, and the error message appears.
Sometimes, you may not see this error immediately on the front end if your site serves a cached version of a page.
A clear sign of the problem is when you can’t access your WordPress admin dashboard, since the backend almost always requires a live database connection.
Several issues – such as incorrect database credentials, a corrupted database, or an overloaded server – can disrupt the connection between WordPress and its database.
To fix “Error establishing a database connection” in WordPress, start by verifying your database credentials in the wp-config.php file and checking if the database is online and accessible.
If the problem persists, repair the WordPress database or replace any corrupted core files. If that doesn’t work, create a new database, update your site’s URL, and confirm that your domain points to the correct host.
If none of these steps solve the issue, reboot your server yourself or contact your hosting provider for assistance.
Before trying any of these solutions, we strongly recommend creating a backup of your WordPress site. This way, you can restore your site if something goes wrong during troubleshooting.
The most common cause of a database connection error is incorrect credentials in your wp-config.php file. This often happens after migrating your site to a new host.
First, locate your correct database credentials in your hosting control panel. Then, compare them with the values in your wp-config.php file.
For Hostinger’s managed WordPress customers, here’s how to do it in hPanel:



If your credentials are correct, the problem stems from the MySQL database server itself. The server could be down or unable to process requests because of a traffic surge.
To confirm this, contact your hosting provider’s support team. Ask if other users on the same server are having issues or if the MySQL server is offline.
If you host another site on the same server, run a quick test to see if those sites are working. If they’re also down, it’s a strong sign that the issue is on your hosting provider’s side.
At Hostinger, you can check the status page for any ongoing server maintenance or reported issues.
If your database tables are corrupted, WordPress can’t retrieve data from them. Fortunately, WordPress includes a built-in database repair mode that you can activate.
Follow these steps to repair your database:
define('WP_ALLOW_REPAIR', true);
Once the process finishes, revisit your website. If it loads correctly, remove the line define(‘WP_ALLOW_REPAIR’, true); from your wp-config.php file immediately. Leaving it enabled is a security risk because anyone could access that repair page.
Corrupted WordPress core files can also interfere with the database connection. This often happens during a manual update or due to a file transfer error. You can fix it by replacing your core files with a fresh copy.
Here are the instructions:

This process replaces all the core files without touching your content, themes, or plugins. After the upload is complete, check your website again.
If your database is severely corrupted and can’t be repaired, the best solution is to restore it from a backup. This process involves creating a new, empty database and importing your backup file into it.
Here’s how to do it with Hostinger:


If the error appears right after migrating your WordPress site to a new server or domain, it indicates a misconfigured site URL in the database. You can fix this by updating the WordPress site URL in phpMyAdmin.
Warning! Running SQL queries directly can be risky if you’re not careful. Always back up your database before making changes in phpMyAdmin.
Follow these steps:
UPDATE wp_options SET option_value = replace(option_value, 'http://www.old-domain.com', 'http://www.new-domain.com') WHERE option_name = 'home' OR option_name = 'siteurl'; UPDATE wp_posts SET guid = replace(guid, 'http://www.old-domain.com','http://www.new-domain.com'); UPDATE wp_posts SET post_content = replace(post_content, 'http://www.old-domain.com', 'http://www.new-domain.com'); UPDATE wp_postmeta SET meta_value = replace(meta_value,'http://www.old-domain.com','http://www.new-domain.com');

After a migration, it’s crucial that your domain’s DNS settings point to your new hosting provider. If your domain still points to the old host, WordPress will attempt to connect to the old database, which causes an error.
To check this, verify your domain’s nameservers. If both your domain and website are hosted at Hostinger, the nameservers are set automatically. In this case, you don’t need to change anything.
If you host your website with Hostinger but registered your domain elsewhere, you can find your nameservers under Websites → Website list → Dashboard → Hosting Plan → Plan details.

Next, use a tool like DNS Checker to confirm where your domain is currently pointing. If the nameservers are incorrect, log in to your domain registrar’s control panel and point them to Hostinger’s nameservers.
If you registered your domain with Hostinger but host your site with another provider, the process is similar but reversed. You’ll need to get the correct nameservers from your hosting provider, then update them in Hostinger:

After changing nameservers, keep in mind that DNS updates can take up to 24 hours to propagate worldwide.
If you’ve tried all the previous steps and the error still persists, it’s time to contact your hosting provider. Their support team has server-level access and the right tools to diagnose complex issues.
Hostinger’s Customer Success team is available 24/7 to help resolve these problems.
If you use a virtual private server (VPS), you also have the option to reboot it. A reboot can clear temporary glitches or stop processes that are consuming too many server resources and blocking the database from responding.
For Hostinger VPS customers, the Reboot VPS button is available on your VPS Overview page.

Always back up your VPS before rebooting it. This way, you can quickly restore your site if something unexpected happens during the restart.
Preventing database connection errors in WordPress involves enabling automated site backups, optimizing database tables, using trusted plugins and themes, choosing a reliable hosting provider, and monitoring your site’s resource usage.
After fixing “Error establishing a database connection” in WordPress, the next step is to keep your database running smoothly to avoid future problems.
A clean and optimized database not only reduces the risk of corruption but also improves your site’s overall speed.
To maintain long-term site health, learn how to optimize your WordPress database using the right tools and best practices. This will help your site stay stable and perform at its best as it grows.
All of the tutorial content on this website is subject to Hostinger's rigorous editorial standards and values.