Troubleshooting database connection errors

Databases Updated Jan 15, 2026

Fixing Database Errors

Common database connection problems and how to solve them.

Error: "Error establishing a database connection"

Causes:

Fix:

  1. Check wp-config.php (WordPress) or config file
  2. Verify DB_NAME, DB_USER, DB_PASSWORD, DB_HOST
  3. Confirm database exists in cPanel
  4. Ensure user is assigned to database

Error: "Access denied for user"

Fix:

  1. Verify the password is correct
  2. Check username includes cPanel prefix
  3. Ensure user has privileges on the database

Error: "Unknown database"

Fix:

  1. Check the database name spelling
  2. Ensure you include the cPanel prefix (e.g., cpuser_dbname)
  3. Create the database if it doesn't exist

Error: "MySQL server has gone away"

Causes:

Fix: Optimise your queries or contact support.

Checking Connection

Create a test PHP file:

<?php
$conn = mysqli_connect("localhost", "user", "pass", "dbname");
if (!$conn) { die("Failed: " . mysqli_connect_error()); }
echo "Connected!";
?>

Was this article helpful?