DEV Community

Cover image for WordPress: How to solve "Error establishing a database connection"
Skuzzy Topten
Skuzzy Topten

Posted on • Updated on

WordPress: How to solve "Error establishing a database connection"

The "Error Establishing a Database Connection" in WordPress typically occurs when WordPress can't connect to your database due to incorrect database credentials, a problem with the server, or a corrupted database. Here's a step-by-step guide to troubleshoot and resolve the issue:

Check Database Credentials in wp-config.php

  • Ensure the database name, username, password, and host are correct in the wp-config.php file.
  • Navigate to the root directory of your WordPress installation, find wp-config.php, and verify these lines

Image description

XAMPP (phpMyadmin)
To check or retrieve the username and password for your MySQL database in XAMPP via phpMyAdmin, follow these steps:

  • Open phpMyAdmin in XAMPP
    Start XAMPP and ensure that Apache and MySQL services are running.
    Open your web browser and go to http://localhost/phpmyadmin.

  • Check the MySQL Username
    By default, the MySQL username for XAMPP is usually root.
    To confirm or change this, click on the "User accounts" tab in the top menu inside phpMyAdmin.

Image description

You’ll see a list of all MySQL users and their corresponding privileges. Look for the user with the Host set to localhost (this is typically the root user).

Image description

  • Check the MySQL Password
    By default, XAMPP does not set a password for the root user, meaning the password field is blank.
    However, if you have set a password for the root user, you won't be able to see the password directly. Instead, you can reset it if needed.

  • Resetting or Setting a Password for MySQL User
    In phpMyAdmin, navigate to "User accounts".
    Find the user you want to reset the password for (likely root), then click Edit Privileges next to the user.

Image description

Scroll down to the Change password section and enter a new password. Confirm the password, and click Go to save the changes.

Image description
Image description

If you've set a password for the root user, remember to update 'DB_NAME', 'DB_USER' and 'DB_PASSWORD' fields in your WordPress configuration (wp-config.php) accordingly.

These steps should help you troubleshoot and resolve the "Error Establishing a Database Connection" in WordPress.

Top comments (0)