WP CLI Error: Error establishing a database connection.

Appearance: Submitting commands via WP CLI, but WordPress in the browser works. This error often occurs when the WP CL interpreter cannot interpret the database connection in wp-config.php correctly. Solution: In 99% of all cases, change the value of the DB_HOST constant from "localhost" to "127.0.0.1". Background: "localhost" is not a fixed IP address. The system now has...

Michael Mai, 04.06.2021

Picture of a beautifully tidy garden

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.

See also

No contributions found