Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2318175
  • 博文数量: 473
  • 博客积分: 12252
  • 博客等级: 上将
  • 技术积分: 4307
  • 用 户 组: 普通用户
  • 注册时间: 2007-10-12 10:02
文章分类

全部博文(473)

文章存档

2012年(8)

2011年(63)

2010年(73)

2009年(231)

2008年(98)

分类: 系统运维

2011-02-18 17:05:21

Definition: The 127.0.0.1 is a special purpose address reserved for use on each computer. 127.0.0.1 is conventionally a computer's loopback address.

Network software and utilities can use 127.0.0.1 to access a local computer's TCP/IP network resources. Messages sent to loopback IP addresses like 127.0.0.1 do not reach outside to the but instead are automatically re-routed by the computer's own back to the receiving end of the TCP/IP stack.

Typically all IP addresses in the range 127.0.0.1 - 127.255.255.255 are reserved for private use, but 127.0.0.1 is by convention the loopback address in almost all cases.

转自:

localhost也叫local ,正确的解释是:本地服务器
127.0.0.1在windows等系统的正确解释是:本机地址(本机服务器)

localhot(local)是不经网卡传输!这点很重要,它不受网络防火墙和网卡相关的的限制。

127.0.0.1是通过网卡传输,依赖网卡,并受到网络防火墙和网卡相关的限制。

一般设置程序时本地服务用localhost是最好的,localhost不会解析成ip,也不会占用网卡、网络资源。

有时候用localhost可以,但用127.0.0.1就不可以的情况就是在于此。猜想localhost访问时,系统带的本机当前用户的权限去访问,而用ip的时候,等于本机是通过网络再去访问本机,可能涉及到网络用户的权限。

MySQL中的localhost和127.0.0.1

1. mysql -h 127.0.0.1 的时候,使用TCP/IP连接,
mysql server 认为该连接来自于127.0.0.1或者是"localhost.localdomain"

2. mysql -h localhost 的时候,是不使用TCP/IP连接的,而使用Unix socket;
此时,mysql server则认为该client是来自"localhost"

3. mysql权限管理中的"localhost"有特定含义:
—— MySQL手册 5.6.4 ..... A Host value may be a hostname or an IP number, or 'localhost' to indicate the local host.


注意:虽然两者连接方式有区别,但当localhost 为默认的127.0.0.1时,两种连接方式使用的权限记录都是以下的1.row的记录(因为记录在前,先被匹配)

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

*************************** 2. row ***************************
                 Host: 127.0.0.1
                 User: root

证明:


shell> mysql -h 127.0.0.1
mysql> status;

Current user:           root@localhost
SSL:                    Not in use
Current pager:          stdout
Using outfile:          ''
Using delimiter:        ;
Server version:         5.1.33-log Source distribution
Protocol version:       10
Connection:             127.0.0.1 via TCP/IP


shell> mysql -h locahost
mysql> status;

Current user:           root@localhost
SSL:                    Not in use
Current pager:          stdout
Using outfile:          ''
Using delimiter:        ;
Server version:         5.1.33-log Source distribution
Protocol version:       10
Connection:             Localhost via UNIX socket

阅读(1888) | 评论(0) | 转发(2) |
给主人留下些什么吧!~~