Short Bytes: Ever wondered why 127.0.0.1 IP address is assigned to localhost? Why not some other IP address like 121.9.1.1 or anything else? The answer to this question lies in the fact that by 1981, 0 and 127 were the only reserved Class A networks. As 0 was used for pointing to a specific host, 127, the last network number, was left for loopback IP address or localhost.
Re: Can't connect to MySQL server on '127.0.0.1' (111) View as plain text Please 'netstat -numeric-hosts -notrim -programs -u -t -l' In my first answer i forgot the -l Without we get active connections, but we want the listening tcp-services where somewhere must by mysqld the easiest test is however harry@srv-rhsoft:$ telnet 127.0.0.1.
You might have definitely heard of 127.0.0.1. You also might be knowing that 127.0.0.1 points to localhost. But, why is localhost‘s IP address 127.0.0.1–why not something else?
Before trying to answer that question, let me tell you a little bit about how does it work. This address is used to establish a connection to the same computer used by the end-user. When we deal with IPv6 address, it’s defined using the connotation of ::1. As IPv6 addresses take over, localhost will be more commonly know as 0:0:0:0:0:0:0:1.
How does 127.0.0.1 work? Why is it called so?
Very often developers use 127.0.0.1 to test their applications. When you try to establish a network connection to the 127.0.0.1 loopback address, it works in the same manner as making a connection with any remote device. However, it avoids connection to the local network interface hardware.
But, why does the localhost IP address starts with 127? Well, 127 is the last network number in a class A network. It has a subnet mask of 255.0.0.0. So, the first assignable address in the subnet is 127.0.0.1.
However, if you use any other numbers from the host portions, it should work fine and revert to 127.0.0.1. So, you can ping 127.1.0.1 if you like.
You might also ask why the last network number was chosen to implement this. Well, the earliest mention of 127 as loopback dates back to November 1986 RFC 990. And, by 1981, 0 and 127 were the only reserved Class A networks.
The class A network number 127 is assigned the “loopback” function, that is, a datagram sent by a higher level protocol to a network 127 address should loop back inside the host. No datagram “sent” to a network 127 address should ever appear on any network anywhere.
As 0 was used for pointing to a specific host, 127 was left for loopback. Some would also call it more sensible to choose 1.0.0.0 for loopback, but that was already given to BBC Packet Radio Network.
Source: SuperUser
Did you find this article helpful? Don’t forget to drop your feedback in the comments section below.
Also Read: Guess What? The Internet Just Slipped From the Hands Of the United States
How could it be? And main question - how to grant ALL privileges on ALL databases from ALL hosts for root?
UPD:
UPD2:
Bunyk
BunykBunyk4,24933 gold badges2424 silver badges5050 bronze badges
4 Answers
As you can see here, a UNIX mysqld uses sockets if used without a host name or with the host name
localhost
.So it makes a difference, and in the GRANT system this difference becomes evident.
glglglglglgl69.4k77 gold badges9999 silver badges169169 bronze badges
I know this tread is old, however was most probably not correctly answered.
By default, mysql does a name resolve so 127.0.0.1 and localhost will resolve in the same. However, you can switch the name resolution off in my.cnf:
skip-name-resolve = 1
Then localhost and 127.0.0.1 will NOT be the same anymore. So you either keep the name resolution, or restrict yourself to only using localhost in your grants or only 127.0.0.1BUT: If you do the latter one, you will have to access our database with those credentials as well.
Ingo RatsdorfIngo Ratsdorf
Log in through 127.0.0.1 and execute this statement:
You will probably see something like
I just confirmed on my local install and it seems MySQL won't auto-resolve the host name. You can either add another grant for
Matt DodgeMatt Dodgelocalhost
or just use 127.0.0.18,26333 gold badges2929 silver badges4949 bronze badges
This caused issues in setting up a local dev environment on MacOS.
Several script functions, say
mysqli_connect()
in php might be using localhost
to connect to MySQL: You can't (shouldn't have to) go about replacing localhost
with 127.0.0.1
in every script.Tried fixing this by adding
bind-address=localhost
, socket=/var/mysql/mysql.sock
, socket=/tmp/mysql.sock
etc. to the my.cnf file, but that didn't work.To resolve the issue (on MacOS), note that the
mysql.default_socket
setting in /etc/php.ini
file points to /var/mysql/mysql.sock
, while MySQL's default_socket is /tmp/mysql.sock
.So, either edit your
php.ini
file, or create a softlink to MySQL's default_socket:P.S - 127.0.0.1 is treated as a TCP connection and localhost as unix socket connection by MySQL: details here.
Nitin NainNitin Nain