Question: Does anyone know what the error could be when I can connect to my MySQL server via localhost but not via 127.0.0.1? AFAIK, these should be routed identically and no additional TCP layer should be created when using the IP.

```
$ mysql -u root -h localhost -D test # works
$ mysql -u root -h 127.0.0.1 -D test # does not work
(127.0.0.1 does map to localhost/vice versa)

```

The table permissions are explicitly set to include both methods.

Answer: 
The MySQL client library overrides localhost to use a Unix socket instead of a TCP/IP connection to 127.0.0.1. If you can connect to localhost but not 127.0.0.1, that suggests that it's either firewalled or not listening on 127.0.0.1.
MySQL client infers the protocol from the provided host.

> 
> For a given connection, if the transport protocol is not specified explicitly, it is determined implicitly. For example, connections to localhost result in a socket file connection on Unix and Unix-like systems, and a TCP/IP connection to 127.0.0.1 otherwise.
> 
> 
> 

Source: [MySQL Docs](https://dev.mysql.com/doc/refman/5.7/en/transport-protocols.html)

If you are unable to connect to the server using `127.0.0.1` as *host*, it probably means that the server is not running on a TCP port or port 3306 (which is the default when not provided). In that case you can connect to it only over the socket file.