PHP MYSQL-127.0.0.1和本地主机之间的区别 [英] PHP MYSQL - Difference between 127.0.0.1 and localhost

查看:42
本文介绍了PHP MYSQL-127.0.0.1和本地主机之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在运行OS X的imac上遇到一个奇怪的问题.对于我的框架和CMS配置文件,如果我使用host:localhost(在数据库设置中),则会产生错误,并且CMS/框架无法连接到数据库.但是,如果我将localhost替换为127.0.0.1,则一切似乎都可以正常工作.由于本地主机已解析为127.0.0.1,所以我想知道导致此行为的php/mysql配置可能是什么问题. 我在Wordpress,Cake和CodeIgniter上遇到了这个问题.

I am encountering a strange problem on my imac running OS X. For my frameworks and CMS configuration files if I use host: localhost (in db settings) an error is produced and the CMS/framework cannot connect to the database. However if I replace localhost to 127.0.0.1 everything seems to work fine. Since localhost is resolved to 127.0.0.1 I'd like to know what might be the problem with my php/mysql configurations that is resulting into this behavior.? I encountered this problem with Wordpress, Cake and CodeIgniter.

推荐答案

localhost将使MySQL客户端尝试在标准目录中使用UNIX套接字.如果那不存在或在其他地方,您将无法连接. 127.0.0.1始终使用TCP连接.

localhost will cause the MySQL client to try a UNIX socket in a standard directory. If that doesn't exist or is somewhere else, you won't be able to connect. 127.0.0.1 always uses a TCP connection.

请参见手册,C. 5.2.2.无法连接到[本地] MySQL服务器.

这篇关于PHP MYSQL-127.0.0.1和本地主机之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆