Point de vue différents :)
Ici, lorsqu'on utilise "localhost", la connexion va se faire par une socket et lorsqu'on utilise "127.0.0.1", la connexion se fera par tcp. On pourrait se dire que le comportement est anormal, mais en fait, non :
"The patch won't be added as then "localhost" has two meanings - one time meaning "use the unixdomain socket in the default location" and one time actually "resolve localhost and use TCP" as it is taught in many places that "localhost" in MySQL has the first meaning we keep it there."
La socket est déterminée ici dans le php.ini :
; Default socket name for local MySQL connects. If empty, uses the built-in
; MySQL defaults.
mysql.default_socket =