Get your free beta license ↗
Databases · MariaDB

WordPress says “Error establishing a database connection”

Last updated 30 Nov 2026
Summary

WordPress shows Error establishing a database connection on every page. MariaDB is down or the database user or password in wp-config.php differs from what MariaDB has, and two commands show which.

Symptoms

Every page of the site shows Error establishing a database connection.

Cause

WordPress could not connect to MariaDB using DB_NAME, DB_USER, DB_PASSWORD and DB_HOST from wp-config.php.

MariaDB may be down. The database user or password in wp-config.php may also differ from what MariaDB has, as can happen after you copy a site from another server.

Resolution

  1. Try connecting with the values from wp-config.php.

    mariadb -u example_wp -p example_wp
  2. If the database user or password is wrong, the command prints this error.

    Output
    ERROR 1045 (28000): Access denied for user 'example_wp'@'localhost' (using password: YES)
  3. If MariaDB is down, the command prints this error on AlmaLinux.

    Output
    ERROR 2002 (HY000): Can't connect to local server through socket '/var/lib/mysql/mysql.sock' (2)
  4. If MariaDB is down, check its state and start it.

    urbestack-service-list --name mariadb
    urbestack-service-restart --name mariadb
  5. If the password is wrong, list the customer's database users and their grants.

    urbestack-database-user-list --owner USER
  6. Set a new password for the database user. The command reads the password from standard input.

    urbestack-database-user-set --name example_wp --password-stdin
  7. Put the same password in DB_PASSWORD in wp-config.php. The value of DB_HOST is localhost.

  8. Run the connection command again with the values from wp-config.php to check that it connects. If it still prints one of the errors above, follow the steps for that error.