What is the difference between users added to mysql with host set to 127.0.0.1 and localhost?
I noticed that there are always entries for the root user with the host set to 127.0.0.1
and another with the host set to localhost
. My question is why there are two entries, four if you include MACHINE_NAME
and ::1
, where MACHINE_NAME is the actual machine name, for example appServer2.
I wondered why there are multiple entries. Are there cars where localhost
it is not allowed 127.0.0.1
? Are their times when starting mysql will try to connect through the servers' frontend?
I've seen this question before, but nobody answered why "127.0.0.1" and "localhost" are always separate entries.
source to share
In MySQL on unix systems, this localhost
is a special value. It is used to identify connections over a local socket rather than TCP / IP.
(Confusingly, outside of MySQL, a hostname localhost
usually resolves to the IP address 127.0.0.1. To reduce confusion, think of "localhost" in MySQL as meaning something completely different. It might be better if the name "local_socket_ connection" ". )
These are separate entries because "localhost" will never refer to a TCP / IP connection, and an IP address will never refer to a local socket.
Link: https://dev.mysql.com/doc/refman/5.7/en/connecting.html
Default hostname
localhost
. On Unix this has a special meaning, as described below.
On Unix, MySQL programs treat the hostname on
localhost
purpose, which may be different than expected when compared to other networking programs. For connections tolocalhost
, MySQL programs try to connect to the local server using a Unix socket file. This occurs even if an option is specified--port
or-P
to specify a port number. For the client to establish a TCP / IP connection to the local server, use--host
or-h
to specify the hostname value127.0.0.1
or the IP address or local server name. You can also specify the connection protocol explicitly, even for localhost, using the parameter--protocol=TCP
. For example:
source to share