Fixing Database Errors
Common database connection problems and how to solve them.
Error: "Error establishing a database connection"
Causes:
- Wrong database credentials
- Database server is down
- Database doesn't exist
Fix:
- Check wp-config.php (WordPress) or config file
- Verify DB_NAME, DB_USER, DB_PASSWORD, DB_HOST
- Confirm database exists in cPanel
- Ensure user is assigned to database
Error: "Access denied for user"
Fix:
- Verify the password is correct
- Check username includes cPanel prefix
- Ensure user has privileges on the database
Error: "Unknown database"
Fix:
- Check the database name spelling
- Ensure you include the cPanel prefix (e.g., cpuser_dbname)
- Create the database if it doesn't exist
Error: "MySQL server has gone away"
Causes:
- Query took too long
- Packet too large
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!";
?>