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 DB_HOST constant from "localhost" to "127.0.0.1".
Background: "localhost" is not a fixed IP address. The system now has several options 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.