RackUp IT - View Cloud Hosting Plans

Get started now or speak directly with our engineering team for specialized assistance.

Logo
DevelopmentWEB & APPCalculatorTOOLServicesProductBlogOur TeamCareers
View Plans
Home>Blog>How to Fix “Error Establishing a Database Connection” in WordPress
WordPress Hosting

How to Fix “Error Establishing a Database Connection” in WordPress

Alex Vance
Alex Vance
Published Oct 29, 2026•✓ Verified Expert Reviewed•5 min read
Fix error establishing a database connection in WordPress cover

Key Takeaways

  • ✓WordPress loaded but couldn't connect to its MySQL or MariaDB database.
  • ✓Start with DB_NAME, DB_USER, DB_PASSWORD and DB_HOST in wp-config.php.
  • ✓Out-of-memory kills and full disks are the usual reasons MySQL stops.
  • ✓Remove WP_ALLOW_REPAIR as soon as a repair finishes.

Table of Contents

  • •How to Fix “Error Establishing a Database Connection” in WordPress
  • •First: Is It the Front End, the Admin, or Both?
  • •Step 1: Check the Credentials in wp-config.php
  • •Step 2: Check DB_HOST
  • •Step 3: Check the Database Server Is Running
  • •Step 4: Repair a Corrupted Database
  • •Step 5: The Error Comes and Goes (Too Many Connections or an Overloaded Server)
  • •Step 6: Check the Site URL After a Migration
  • •How to Stop It Happening Again
  • •Frequently Asked Questions
  • •Get Help With WordPress Databases

How to Fix “Error Establishing a Database Connection” in WordPress

“Error establishing a database connection” means WordPress loaded, tried to connect to its MySQL or MariaDB database, and failed. Every page needs the database, so the whole site shows that one white page. The cause is almost always one of five things: wrong credentials in wp-config.php, a database server that is down, a wrong database host, a corrupted database, or a server that ran out of memory or connections. This guide walks through them in the order that finds the problem fastest.

Quick answer: open wp-config.php and check DB_NAME, DB_USER, DB_PASSWORD and DB_HOST against your hosting dashboard. If they’re right, check that the database server is running and has free memory and disk space.

First: Is It the Front End, the Admin, or Both?

Open your site and then /wp-admin:

  • Both show the error: WordPress can’t reach the database at all. Start with Step 1.

  • The admin shows “One or more database tables are unavailable. The database may need to be repaired.” The connection works but tables are damaged. Go to Step 4.

  • It comes and goes: the database server is overloaded or restarting. Go to Step 5.

Step 1: Check the Credentials in wp-config.php

WordPress reads its database settings from wp-config.php in the site root. Open it with your file manager or SFTP and find these four lines:

define( 'DB_NAME', 'database_name' );
define( 'DB_USER', 'database_user' );
define( 'DB_PASSWORD', 'password' );
define( 'DB_HOST', 'localhost' );

Compare each value with the database details in your hosting dashboard. Common mistakes:

  • A password changed in the dashboard but not in wp-config.php (or the other way round).

  • A database or user name missing a prefix your host adds, such as account_wpdb.

  • A stray space or quote inside the value after a copy and paste.

  • After a migration, the old host’s values still in the file.

You can test the credentials directly from SSH or a terminal:

mysql -u database_user -p -h localhost database_name

If that fails with “Access denied”, the user, password or host is wrong, or the user has no rights on that database. Reset the password in your dashboard and update wp-config.php.

Step 2: Check DB_HOST

localhost is correct when the database runs on the same server as WordPress. Many setups use something else:

  • A separate database server or managed database: its hostname or IP, sometimes with a port, such as db.example.com:3306.

  • Docker or Compose: the database service name, such as db, not localhost.

  • A socket path on some servers: localhost:/var/run/mysqld/mysqld.sock.

If you moved hosts recently, this is the most likely culprit. Our guide to moving WordPress to a new host covers updating it.

Step 3: Check the Database Server Is Running

If the credentials are right, the database may simply be down. On a VPS:

sudo systemctl status mysql     # or: mariadb
sudo systemctl restart mysql
sudo journalctl -u mysql --since "1 hour ago"

Look for the reason it stopped. Two causes come up again and again:

  • Out of memory: run dmesg -T | grep -i "killed process". If you see mysqld, the kernel’s out-of-memory killer stopped it. You need more RAM, a smaller innodb_buffer_pool_size, or fewer PHP workers competing for memory.

  • Disk full: run df -h. MySQL can’t start or write when the disk is full; old logs and backups are the usual suspects.

On managed hosting you can’t restart MySQL yourself, so contact support with the time the error started.

Step 4: Repair a Corrupted Database

If the admin says tables need repair, WordPress has a built-in repair tool. Add this line to wp-config.php above “That’s all, stop editing!”:

define( 'WP_ALLOW_REPAIR', true );

Then visit https://yoursite.com/wp-admin/maint/repair.php and click “Repair Database”. This page works without logging in, so remove the line again as soon as you’re done.

With WP-CLI you can do the same from the command line:

wp db check
wp db repair

Take a backup first (wp db export) if the database still responds.

Step 5: The Error Comes and Goes (Too Many Connections or an Overloaded Server)

An intermittent error usually means the database is reachable but overwhelmed:

  • Too many connections: MySQL’s max_connections limit was hit, often during a traffic spike or a bot attack on wp-login.php or xmlrpc.php.

  • Slow queries piling up: a plugin running heavy queries on every page view.

  • Not enough RAM: MySQL being restarted repeatedly by the out-of-memory killer.

Check the MySQL error log and your access log for the time of the errors. Blocking abusive bots, adding page caching and moving to a plan with more RAM fix most cases.

Step 6: Check the Site URL After a Migration

If only some pages fail after a move, check that siteurl and home in the wp_options table match your new domain, and that the table prefix in wp-config.php ($table_prefix) matches the tables in the database. A wrong prefix makes WordPress think it isn’t installed.

How to Stop It Happening Again

  • Keep database credentials in one place and update wp-config.php whenever you change them.

  • Watch RAM and disk space; most “random” database errors are a server out of one or the other.

  • Keep daily backups you can restore with one click, so a corrupted database is a five-minute fix.

  • Remove plugins you don’t use; each one can add queries.

Frequently Asked Questions

What causes “Error establishing a database connection” in WordPress?
WordPress can’t connect to its database. The usual causes are wrong credentials in wp-config.php, a wrong DB_HOST, a stopped or crashed MySQL server, a corrupted database, or a server out of memory or connections.

Will I lose my content?
Usually not. The posts and pages are still in the database; WordPress just can’t reach them. Only real corruption or a deleted database puts content at risk, which is why backups matter.

Why does it happen only sometimes?
An intermittent error points to an overloaded database: too many connections at once, slow queries or MySQL being restarted when the server runs out of RAM.

Is it safe to leave WP_ALLOW_REPAIR on?
No. The repair page doesn’t require a login while it’s enabled. Remove the line from wp-config.php as soon as the repair finishes.

How do I fix it after moving WordPress to a new host?
Update DB_NAME, DB_USER, DB_PASSWORD and DB_HOST in wp-config.php to the new host’s values, make sure the database was imported, and check that the table prefix matches.

Get Help With WordPress Databases

On RackUp Cloud WordPress hosting each site runs in its own container with reserved RAM, automated daily offsite backups and one-click rollback, so a broken database is a restore away. If you’re moving from another host, our team migrates WordPress sites for free. Plans start at $2.49 a month. See plans.

← Previous ArticleDjango Hosting in 2026: Where to Host a Django App
Interactive 60-Second Tool

Unsure Which Cloud Hosting Plan Fits Your Site?

Answer 4 quick diagnostic questions to estimate the server CPU, RAM and storage you need with transparent pricing.

Free Migration 99.9% Uptime Target
Calculate My Hosting Build
Alex Vance
Written ByAlex Vance

Cloud Infrastructure Engineer.

99.9% Uptime Target

RackUp IT - View Cloud Hosting Plans

View Hosting Plans

View Hosting Plans

CONTENTS

  • How to Fix “Error Establishing a Database Connection” in WordPress
  • First: Is It the Front End, the Admin, or Both?
  • Step 1: Check the Credentials in wp-config.php
  • Step 2: Check DB_HOST
  • Step 3: Check the Database Server Is Running
  • Step 4: Repair a Corrupted Database
  • Step 5: The Error Comes and Goes (Too Many Connections or an Overloaded Server)
  • Step 6: Check the Site URL After a Migration
  • How to Stop It Happening Again
  • Frequently Asked Questions
  • Get Help With WordPress Databases

Categories

  • WordPress Hosting
  • Cloud Hosting
  • DevOps & Tutorials
  • Networking & Security
  • Web Hosting / Managed Cloud
  • VPS Hosting
  • Server Stack
  • E-Commerce
  • Hosting & SEO
  • Hosting Benchmarks
  • Cloud Backup & DevOps
  • Managed VPS

Recent Posts

  • Django Hosting in 2026: Where to Host a Django App
  • How to Install Docker on Ubuntu (26.04, 24.04 and 22.04)
  • How to Install an SSL Certificate on WordPress (and Fix Mixed Content)

Tags

WordPressMySQLTroubleshootingErrorsDjangoPythonApp HostingComparisonDockerUbuntuLinuxVPSTutorialHerokuVercelMigrationManaged WordPressBackupsWP-CLIStagingUFWFirewallSecurityJavaSpring BootWeb HostingBeginnersGuideCoolifyDokployDokkuKamalSelf-HostedSystem RequirementsNode.jsPortainerDockgeToolsWordPress HostingNetworkingRailwayRenderDedicated ServerPerformanceUpgradeNext.jsReactDocker ComposeVultrDigitalOceanBluehostDocker DesktopDevOpsCloud HostingApacheWeb ServerNginxHTTPSRedirectsSSLLinodeAkamaiHostingerInstallFirebaseSupabaseAppwriteBackendFlaskFastAPIDomainsSEONetlifyCloudflarePHPDeveloper HostingAgency HostingClient SitesKubernetesTraefikCaddyReverse ProxySiteGroundMonitoringPrometheusPostgrescPanelControl PanelGunicornDeploymentJavaScriptnvmContainersLoad BalancingScalingVPS HostingConfigurationLet's EncryptCertbotChecklistDNSCloudwaysKinstaWP EngineLaraveldocker logsDisk Spacedocker execiptablesfirewalldError Codes404 Not Found403 ForbiddenLinux PermissionsSELinuxOracle CloudAmpere A1ARMFree TierOCIRegions502 Bad GatewayPHP-FPMcPanel HostingAffordable HostingCheap VPSCloud VPSHosting BenchmarksSpeed OptimizationSpeed Up WordPressCore Web VitalsNGINX FastCGIOPcacheWooCommerceRedis CachePHP WorkersE-CommerceSecure WordPress HostingWordPress SecurityContainer IsolationWordPress HardeningWordPress StagingStaging SiteWP StagingScalable HostingHigh Traffic WordPressUK Web HostingManaged VPSLeeds Web HostingWooCommerce PerformanceStatic IPReserved IPOCI VNICOCI BackupRcloneDisaster RecoveryManaged HostingVPS BenchmarkWest Yorkshire RetailManaged VPS HostingUK Server LatencyPort MappingBangladeshidaho hostingCloudPanelidaho webhostingManaged Wordpress VPSManaged Cloud

Related Posts

Install SSL on WordPress guide coverWordPress Hosting
Oct 23, 2026

How to Install an SSL Certificate on WordPress (and Fix Mixed Content)

How to move a WordPress site to HTTPS: get a free certificate, update the site URLs, fix mixed content, force HTTPS at the server, and avoid the common redirect loop.

Read Article →
WordPress migration checklist coverWordPress Hosting
Oct 15, 2026

WordPress Migration Checklist: Before, During and After the Move

Use this WordPress migration checklist to move your site without lost data, broken links or downtime: preparation, the move itself, and post-launch checks.

Read Article →
Move a WordPress site to a new host guide coverWordPress Hosting
Oct 14, 2026

How to Move a WordPress Site to a New Host (Without Downtime)

A step-by-step guide to transferring a WordPress site to a new host with a plugin or manually, testing it before you switch DNS, and avoiding downtime and broken links.

Read Article →
Logo

Expert Web & App Development, UI/UX Design, Branding, and Consulting to scale your business.

Company

  • About Us
  • Blog
  • Contact
  • Our Team
  • Careers

Services

  • Web Development
  • App Development
  • UI/UX Design
  • Consulting

Subscribe to our newsletter

© 2026 Rackup IT Solution. All rights reserved.

Privacy PolicyTerms of Service