可能有很多朋友都会碰到一个问题不知道.0.0.1与localhost有什么区别,但是有的时间会发现使用localhost连接不了,但是改成.0.0.1即可了连接了,那么他们会有什么区别呢,下面我给大家介绍。
mysql-h.0.0.1的时候,使用TCP/IP连接,mysqlserver认为该连接来自于.0.0.1或者是localhost.localdomainmysql-hlocalhost的时候,是不使用TCP/IP连接的,而使用Unixsocket;此时,mysqlserver则认为该client是来自localhostmysql权限管理中的localhost有特定含义:注意:虽然两者连接方式有区别,但当localhost为默认的.0.0.1时,两种连接方式使用的权限记录都是以下的1.row的记录(因为记录在前,先被匹配)
***************************1.row***************************Host:localhostUser:root......***************************2.row***************************Host:.0.0.1User:root
证明:shellmysql-h.0.0.1mysqlstatus;Currentuser:root
localhostSSL:NotinuseCurrentpager:stdoutUsingoutfile:Usingdelimiter:;Serverversion:5.1.33-logSourcedistributionProtocolversion:10Connection:.0.0.1viaTCP/IPshellmysql-hlocahostmysqlstatus;Currentuser:rootlocalhostSSL:NotinuseCurrentpager:stdoutUsingoutfile:Usingdelimiter:;Serverversion:5.1.33-logSourcedistributionProtocolversion:10Connection:LocalhostviaUNIXsocket发现问题
昨天在帮同事编译安装Linux环境时,遇到一个问题:
Web服务器是apache,数据库是MySQL。
于是写了一个测试连接数据库的PHP页面:
$mysql=mysql_connect(localhost,root,);
打开