Today I opened a new server. When the code was moved there, the database could not be connected. I took a look. , it turns out that changing the configuration from 127.0.0.1 to localhost is enough. Take a look at the differences between the two below.
Many people will be exposed to this IP address 127.0.0.1. Maybe you will ask what address is 127.0.0.1? In fact, 127.0.0.1 is a loopback address, referring to the local machine, and is generally used for testing. People often use ping 127.0.0.1 to check whether the local IP/tcp is normal. If it can be pinged, it can be used normally.
For most people who are used to using localhost, it essentially points to the local IP address 127.0.0.1. There is a configuration file in the operating system that binds localhost to 127.0.0.1. It can be understood as the meaning of local host.
What is the difference between localhost and 127.0.0.1?
I believe some people will say it is a local IP. Someone once said that using 127.0.0.1 is better than localhost and can save one parsing.
It seems that some people are still unclear about this issue. In fact, there is a difference between the two.
localhost is also called local. The correct explanation is: local server
The correct interpretation of 127.0.0.1 in Windows and other systems is: local address (local server)
Their resolution is through the local host file, and windows automatically resolves localhost to 127.0.0.1
Localhot (local) is transmitted without a network card! This is important because it is not subject to restrictions related to network firewalls and network cards.
127.0.0.1 is transmitted through the network card, relies on the network card, and is subject to restrictions related to network firewalls and network cards.
Generally, when setting up a program, it is best to use localhost for local services. Localhost will not be resolved into IP, and it will not occupy network cards or network resources.
Sometimes it is possible to use localhost, but not 127.0.0.1. This is the case. I guess that when accessing localhost, the system provides the permissions of the current user of the local machine to access. When using IP, it means that the local computer accesses the local machine through the network, which may involve the permissions of the network user.
Original reference: http://blog.csdn.net/xifeijian/article/details/12879395