WordPress runs on MySQL, so when the database throws an error, your entire site can go down. This guide walks you through the most frequent MySQL errors—like “Error establishing a database connection,” “Too many connections,” and “Table doesn’t exist”—and shows you how to fix them step by step. You’ll learn quick checks, phpMyAdmin repairs, and when to contact your host.
What You’ll Need
- Access to your WordPress admin dashboard (if it still loads)
- FTP or File Manager access to your site’s files
- phpMyAdmin or another MySQL database tool (usually available in cPanel or your hosting control panel)
- Your database credentials (username, password, database name, host) — found in your wp-config.php file
- A recent backup of your site and database (strongly recommended)
Step-by-Step
1. Identify the Exact Error Message
Write down the full error text. It tells you which problem you’re dealing with:
- “Error establishing a database connection” — usually wrong credentials, corrupted database, or server overload.
- “Too many connections” — your site or server is hitting the MySQL connection limit.
- “Table ‘wp_options’ doesn’t exist” — a corrupted table or incomplete upgrade.
- “Can’t connect to local MySQL server through socket” — MySQL service is down or unreachable.
2. Check Your wp-config.php Credentials
Open wp-config.php from your site’s root directory (via FTP or File Manager). Look for these lines:
define('DB_NAME', 'your_db_name');
define('DB_USER', 'your_db_user');
define('DB_PASSWORD', 'your_db_password');
define('DB_HOST', 'localhost');
Verify each value with your hosting control panel. Common mistakes: extra spaces, wrong password, or a different host (sometimes it’s a specific hostname like mysql.example.com).
3. Repair Corrupted Tables via phpMyAdmin
If the credentials are correct, the database may be corrupted:
- Log into phpMyAdmin (usually at
yourdomain.com/phpmyadminor in cPanel). - Select your WordPress database from the left sidebar.
- Scroll down and click “Check All” at the bottom.
- From the “With selected:” dropdown, choose “Repair table.”
- Click “Go.” phpMyAdmin will attempt to repair any corrupted tables.
If repair fails, you may need to restore from a backup.
4. Fix the “Too Many Connections” Error
This usually means your site is getting too much traffic or a plugin is causing a connection leak.
- Log into your hosting control panel and restart MySQL if possible (some hosts allow this).
- If you can access WordPress, deactivate all plugins by renaming the
wp-content/pluginsfolder toplugins_oldvia FTP. This forces WordPress to disable all plugins. - If the error disappears, reactivate plugins one by one to find the culprit.
- If you can’t access WordPress, check your hosting provider’s resource limits. You may need to upgrade your plan or enable a caching plugin to reduce database queries.
5. Check MySQL Server Status
If you see “Can’t connect to local MySQL server,” the database server itself may be down. In cPanel, go to “MySQL Databases” or “Database Status” to see if it’s running. If not, contact your host — they usually restart it quickly.
6. Verify Table Prefix
If you get “Table ‘wp_users’ doesn’t exist,” check your wp-config.php for the table prefix:
$table_prefix = 'wp_';
If your database uses a different prefix (e.g., myprefix_), update this line to match. You can see the actual table names in phpMyAdmin.
7. Update Database Host if Needed
Some hosts use a specific hostname like mysql123.example.com instead of localhost. Check your hosting welcome email or control panel for the correct host. Update the DB_HOST value in wp-config.php.
8. Repair via WP-CLI (Advanced)
If you have SSH access, you can use WP-CLI:
wp db repair
This runs the same repair as phpMyAdmin but from the command line.
9. Restore from Backup
If nothing works and you have a recent backup, restore both the database and files. Most hosts offer a one-click restore in cPanel or a backup tool. This is the safest last resort.
Common Mistakes
- Editing wp-config.php with a text editor that adds BOM — use a plain text editor like Notepad++ or a code editor, not Word.
- Using the wrong database name — sometimes hosts prefix your database name with your username (e.g.,
user_wpdb). - Repairing the wrong database — make sure you select the correct database in phpMyAdmin.
- Not backing up before making changes — always back up first.
- Changing the table prefix manually — this breaks the site unless you also update all table names in the database.
Tips
- Keep your WordPress core, themes, and plugins updated — outdated software can cause database errors.
- Use a caching plugin (like W3 Total Cache or WP Super Cache) to reduce database load.
- Regularly optimize your database using plugins like WP-Optimize to keep it healthy.
- If you’re on shared hosting, consider moving to a managed WordPress host that handles MySQL automatically.
- Always keep a recent backup offsite (e.g., in cloud storage).
Troubleshooting
If the steps above don’t resolve the issue:
- Error persists after repair: Try the “Optimize table” option in phpMyAdmin after repairing. If that fails, restore from backup.
- Can’t log into phpMyAdmin: Your database user may not have privileges. Contact your host to reset permissions.
- Site works but admin shows errors: Enable WP_DEBUG in
wp-config.phpto see the exact error. Add these lines:
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
Check wp-content/debug.log for details.
- All else fails: Contact your hosting provider’s support. Provide them with the exact error message and what you’ve tried.
Frequently Asked Questions
Why do I get “Error establishing a database connection” after moving my site?
This usually happens because the database credentials in wp-config.php are still pointing to the old server. Update the DB_NAME, DB_USER, DB_PASSWORD, and DB_HOST to match your new hosting environment.
Can I fix a corrupted database without phpMyAdmin?
Yes, if you have WP-CLI access, run wp db repair. Some hosts also provide a database repair tool in their control panel. If neither is available, you may need to restore from backup.
What does “Too many connections” mean exactly?
MySQL has a maximum number of simultaneous connections (often 100-150 on shared hosting). When this limit is reached, new connections are rejected. This can be caused by high traffic, a plugin making too many queries, or a malicious attack.
How do I change the MySQL table prefix safely?
It’s not recommended unless you have a specific security need. If you must, use a plugin like “Change DB Table Prefix” or manually rename all tables in phpMyAdmin and update $table_prefix in wp-config.php. Always back up first.
What if the error is “Table ‘wp_options’ doesn’t exist”?
This usually means the table is corrupted or missing. Try repairing the table in phpMyAdmin. If it’s missing entirely, you may need to restore the database from backup or reinstall WordPress (which will recreate the core tables).
Can a plugin cause MySQL errors?
Yes, poorly coded plugins can create excessive database queries, cause connection timeouts, or even corrupt tables. Deactivate all plugins by renaming the plugins folder to see if the error resolves.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.
More cards in this drawer
- Secure Boot Battlefield 6 ASUS: Fix & Enable Guide
- Best Tech Websites to Follow for Pros & Beginners
- Second Wind Quest Walkthrough: Where Winds Meet6.00 min/km
- Enshrouded Weapon Upgrade Guide: How to Improve Gear5.00 min/km
- Connect Phone to Controller for Cloud Gaming
- Python Search Highlighting: Snippets & Matches