StartTechnical documentation / snippetsProblem and solutionWP CLI Error: Error establishing a database connection.

WP CLI Error: Error establishing a database connection.

Appearance: Issue commands via WP CLI, but WordPress in the browser works. This error often occurs when the WP CL interpreter cannot correctly interpret the database connection in wp-config.php.

Solution:

In 99% of all cases, change the value of the constant DB_HOST from "localhost" to "127.0.0.1".

Background: "localhost" is not a fixed IP address. The system now has several possibilities for interpretation. In some cases, "localhost" is interpreted as an alias for a socket connection instead of the TCP network protocol. The socket connection does not work via the command line.

Posted in

We will be happy to call you back.

Scroll to Top