The difference between localhost and 127.0.0.1 2

Source: Internet
Author: User
Tags mysql manual

The difference between localhost and 127.0.0.1
What is the difference between localhost and 127.0.0.1? Believe that some people will say is the local IP, has been said that with 127.0.0.1 than localhost better, can be reduced once the resolution. It seems that this entry question is still unclear, in fact, there is a difference between the two.

No1:

LocalHost is also known as local, and the correct explanation is: the native server
The correct explanation of 127.0.0.1 in Windows and other systems is: Native address (native server)

NO2:

Localhot (local) is not transmitted through the network card! This is important, and it is not limited by network firewalls and Nic-related.
The 127.0.0.1 is transmitted through the network card, relies on the network card, and is restricted by the net firewall and the NIC.

The general Setup program when the local service with localhost is the best, localhost will not be resolved to IP, and will not occupy the network card, networking resources.

Sometimes it can be used with localhost, but it is in this case that it is not possible to use 127.0.0.1. Guess localhost access, the system with the current user's permissions to access, while using IP, is equal to the machine is through the network to access the machine, may involve network users ' rights.

The words of his family:

1. When mysql-h 127.0.0.1, use a TCP/IP connection,
MySQL server considers the connection to be from 127.0.0.1 or "Localhost.localdomain"

2. mysql-h localhost, is not using TCP/IP connection, and the use of UNIX sockets;
At this point, MySQL server considers the client to be from "localhost"

3. "localhost" in MySQL Rights management has a specific meaning:
--mysql manual 5.6.4 ..... A Host value is a hostname or an ipnumber, or ' localhost ' to indicate the local Host.

Note: Although there is a difference between the two connection methods, when localhost is the default 127.0.0.1, the permission records used by both connections are the following 1.row records (because the records are first matched)

1. row***************************
Host:localhost
User:root
......
***************************
host:127.0.0.1
User:root

Prove:

Shell> mysql-h 127.0.0.1
mysql> status;
Currentuser:          [email protected]
SSL:                     Not in use
Currentpager:         stdout
usingoutfile:           '
usingdelimiter:        ;
Serverversion:        5.1.33-log Source Distribution
PROTOCOLVERSION:      10
connection:           127.0.0.1via TCP/IP

Shell> mysql-h locahost
mysql> status;
Currentuser:          [email protected]
SSL:                     Not in use
Currentpager:         stdout
usingoutfile:           '
usingdelimiter:        ;
Serverversion:        5.1.33-log Source Distribution
PROTOCOLVERSION:      10
connection:           localhostvia UNIX Socket

shell> mysql-h XXXX (IP)
mysql> status;
Currentuser: [Email protected]
Ssl:not in use
Currentpager:stdout
Usingoutfile: "
Usingdelimiter:;
Serverversion:5.1.33-log Source Distribution
Protocolversion:10
Connection:xxxx (IP) via TCP/IP

The difference between localhost and 127.0.0.1 2

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.