How to Fix Full Database Causing WordPress Connection Error

This Q&A covers the “Error establishing database connection” that can appear when your WordPress database reaches its storage limit. You’ll see where to check your wp-config.php settings, how to view database usage in your hosting panel, and methods to free up space or boost your database quota. Follow these steps to get your site back online quickly.

when I try to login it says "error establishing database connection"

The "Error establishing a database connection" message means WordPress can't connect to your database. Often, this happens when the database credentials in your wp-config.php file are wrong, the database server is down, or there's an issue with the database itself. Here are some steps to troubleshoot:

1. Check Your wp-config.php File

Your wp-config.php file holds the info WordPress uses to connect to the database. Access it via FTP or your host’s file manager in the root of your WordPress install.

  • Location: same directory as wp-content, wp-admin, and wp-includes.
  • Verify these lines:
    • define('DB_NAME', 'your_db_name'); — check that 'your_db_name' matches your actual database name.
    • define('DB_USER', 'your_db_user'); — confirm the database username.
    • define('DB_PASSWORD', 'your_db_password'); — double-check the password.
    • define('DB_HOST', 'localhost'); — most hosts use localhost, but yours might differ.

How to Edit wp-config.php

  1. Back up the file to your computer.
  2. Open it in a text editor (Notepad, VS Code, etc.).
  3. Compare and correct the credentials.
  4. Save and upload the file back to the server.
  5. Reload your site to see if the error is gone.

2. Check Database Server Status

Contact your hosting support to ask if the database server is running properly. They can spot any outages or errors on their end.

3. Repair the Database

WordPress offers a repair tool. Add this line to wp-config.php, above /* That’s all, stop editing! Happy publishing. */:

define('WP_ALLOW_REPAIR', true);

Then visit:

http://yourdomain.com/wp-admin/maint/repair.php

Choose “Repair Database” or “Repair and Optimize Database.” After repairing, remove the WP_ALLOW_REPAIR line for security.

4. Check Your DB_HOST Value

If localhost isn’t correct, consult your host’s docs or support for the right database host address.

5. Disable Plugins via FTP

A faulty plugin can sometimes block connections. To disable all plugins:

  1. Connect via FTP or file manager and go to wp-content.
  2. Rename the plugins folder to plugins_disabled.
  3. Check your site. If it works, rename the folder back and disable plugins one by one to identify the culprit.

could the error be that my database is full

Yes, a full database might trigger the "Error establishing a database connection" message. When your database hits its storage limit, it can no longer accept new data or handle connections. Here’s why and how to check:

Why a Full Database Causes Connection Errors

  • Cannot Write Data: WordPress needs to write posts, comments, settings, and plugin data. If there’s no space, writes fail.
  • Connection Failures: An overfilled database may struggle to handle new connections, causing errors.

How to Check Your Database Usage

  1. Hosting Control Panel: Log in (cPanel, Plesk, or custom panel) and view the MySQL section. It usually shows current size vs. limit.
  2. Contact Support: If it’s unclear, ask your host’s support team to verify if the database is full or near its limit.

If Your Database Is Full

1. Increase Database Storage

  • Upgrade your hosting plan to one with more database space.
  • Purchase extra database storage if your host offers that option.

2. Clean Up Your Database

  • Remove Old Post Revisions: Use a plugin like WP-Optimize or Advanced Database Cleaner.
  • Delete Spam Comments.
  • Remove Unused Plugins and Themes.
  • Clear Transient Options: Use a transient cleaner plugin.
  • Drop Orphaned Tables: Identify leftover tables from deleted plugins, and remove them carefully.
  • Optimize Tables: Run optimization via phpMyAdmin or a plugin like WP-Optimize.

Before You Begin

  • Create a Backup: Always back up your database before any changes.
  • Be Cautious: Deleting the wrong data can break your site. If you’re unsure, get help from a WordPress professional.

Need human WordPress help?

WP Assistant is a free tool created by Atiba Software, a WordPress design and development company located in Nashville, TN. If you need more personalized WordPress assistance let us know, and we’ll get back to you ASAP!