Home  >  Article  >  Database  >  连接数据库localhost和127.0.0.1的区别

连接数据库localhost和127.0.0.1的区别

WBOY
WBOYOriginal
2016-06-07 15:22:521419browse

用JDBC访问Oracle,即java连接本机数据库的时候,地址用localhost和127.0.0.1都可以。但是这两者有什么区别?哪个更好? 有很多人认为这两个是完全一样的,也有人认为127.0.0.1更好,因为是本地IP,不需要从域名解析。其实这两个是有很大区别的: localhost

用JDBC访问Oracle,即java连接本机数据库的时候,地址用localhost和127.0.0.1都可以。但是这两者有什么区别?哪个更好?
有很多人认为这两个是完全一样的,也有人认为127.0.0.1更好,因为是本地IP,不需要从域名解析。其实这两个是有很大区别的:

localhost也叫local ,正确解释为:本地服务器

127.0.0.1在系统的正确解释是:本机地址(本机服务器)

localhot(local)是不经网卡传输!这点很重要,它不受网络防火墙和网卡相关的的限制。访问localhost也不会解析成ip,不会占用网卡、网络资源。

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

这就是为什么有时候用localhost可以访问,但用127.0.0.1就不可以的情况。

所以还是尽量用localhost吧

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn