H
10Corp Premium Hosting

Fixing Database Connection Errors

Last Updated: March 2026 3 min read

Fixing Database Connection Errors

The “Error establishing a database connection” message (common in WordPress) or similar database connectivity errors indicate your website cannot communicate with its MySQL database. Here’s how to diagnose and fix the issue.

Common Causes

  1. Incorrect database credentials in configuration files
  2. Corrupted database or tables
  3. MySQL server is down or overloaded
  4. Exceeded hosting resource limits
  5. Wrong database host setting

Step 1: Verify Database Credentials

The most common cause is incorrect credentials. Check your website’s configuration file:

WordPress (wp-config.php):

define('DB_NAME', 'your_database_name');
define('DB_USER', 'your_database_user');
define('DB_PASSWORD', 'your_password');
define('DB_HOST', 'localhost');

Verify in cPanel:

  1. Go to Databases > MySQL Databases.
  2. Confirm that:
    • The database name exists (remember the cPanel prefix, e.g., cpuser_dbname)
    • The database user exists
    • The user is assigned to the database with appropriate privileges

Test the credentials by logging into phpMyAdmin with the same username and password.

Step 2: Check if MySQL Is Running

If all credentials are correct, the MySQL server may be down:

Via SSH:

mysqladmin -u your_user -p status

Via cPanel:

  • Try opening phpMyAdmin. If it can’t connect, MySQL may be down.
  • Contact 10Corp support to check the MySQL service status.

Step 3: Repair a Corrupted Database

WordPress built-in repair:

  1. Add this line to wp-config.php:
    define('WP_ALLOW_REPAIR', true);
    
  2. Visit https://yourdomain.com/wp-admin/maint/repair.php
  3. Click Repair Database (or Repair and Optimize Database).
  4. Remove the line from wp-config.php after repair (it’s publicly accessible).

Via phpMyAdmin:

  1. Open phpMyAdmin and select the database.
  2. Select all tables (Check All).
  3. From the dropdown, choose Repair table.

Via SSH:

mysqlcheck -u your_user -p --repair your_database_name

Step 4: Check Database Host

Most hosting accounts use localhost as the database host. However, some configurations may require:

  • A specific IP address
  • A socket path (e.g., /var/lib/mysql/mysql.sock)
  • A port number (e.g., localhost:3306)

Check your hosting welcome email or contact 10Corp support for the correct database host.

Step 5: Check Resource Limits

On shared hosting, database connection errors can occur when:

  • Too many simultaneous connections are open
  • Memory limits are exceeded
  • CPU usage is maxed out

Solutions:

  • Optimize your database: Remove unused tables, clean post revisions, delete spam comments.
  • Reduce database queries: Use caching to minimize database load.
  • Close idle connections: Ensure your application properly closes database connections.
  • Upgrade your hosting plan if you’ve outgrown shared hosting.

Step 6: Check for WordPress-Specific Issues

  • Disable plugins: Rename wp-content/plugins to plugins_disabled via FTP/File Manager. If the error resolves, a plugin is the cause.
  • Increase max connections in wp-config.php: This doesn’t change the server limit but can be relevant if you’re customizing database behavior.
  • Check table prefix: Ensure $table_prefix in wp-config.php matches your database tables.

Prevention

  • Regular backups — Back up your database frequently.
  • Keep software updated — Update your CMS, plugins, and themes.
  • Use caching — Reduce the number of database queries.
  • Monitor resources — Keep an eye on hosting resource usage in cPanel.

For persistent database connection issues, contact 10Corp support.

Tags: hosting database mysql troubleshooting wordpress error

Still need help?

Our support team is available 24/7 to assist you.