Why do I receive a database error when specifying "localhost" in the WordPress database connection information? (Specifying 127.0.0.1 allows for a successful connection).
MySQL will try to connect to the unix socket if you tell it to connect to "localhost". If you tell it to connect to 127.0.0.1 you are forcing it to connect to the network socket.
If you have already confirmed that the database connection information is valid and a connection is able to be made when using 127.0.0.1.
If using CloudLinux, please try remounting and updating CageFS with the following command:
The issue may be that the /etc/my.cnf doesn't have a datadir / socket specified.
Default settings for the datadir and socket are noted below: