MySQL localhost/127.0.0.1问题 [英] MySQL localhost / 127.0.0.1 problem
问题描述
我的Macbook上运行的是本地Web服务器,遇到了一个奇怪的问题.我可以使用Sequel Pro之类的程序很好地访问MySQL,密码有效,生活也很棒.
I have a local web server running on my macbook and I've come across a strange problem. I can access MySQL just fine using a program like Sequel Pro, password works and life is great.
在PHP中,如果我的数据库服务器为127.0.0.1,则一切正常.
Within PHP, if I have the db server as 127.0.0.1, everything works as well.
但是,如果我将数据库服务器更改为localhost,则由于'root'@'localhost'错误而导致访问被拒绝.我已经确保正确设置了MySQL套接字,但仍然不能使用localhost.
However, if I change the db server to localhost, I get access denied for 'root'@'localhost' errors. I've made sure the MySQL socket is setup correctly, but still cannot use localhost.
任何见识都会很棒.谢谢!
Any insight would be awesome. Thanks!
推荐答案
除了迈克尔的话,
还有另一个链接: http://dev.mysql.com/doc/refman/5.1/en/connecting.html ,它说:
there's another link: http://dev.mysql.com/doc/refman/5.1/en/connecting.html, it says:
在Unix上,MySQL程序在主机名中特别对待主机名localhost. 与您期望的方式相比其他方式可能有所不同 基于网络的程序.对于与本地主机的连接,MySQL程序 尝试使用Unix套接字文件连接到本地服务器. 即使给--port或-P选项指定了端口,也会发生这种情况 数字.
On Unix, MySQL programs treat the host name localhost specially, in a way that is likely different from what you expect compared to other network-based programs. For connections to localhost, MySQL programs attempt to connect to the local server by using a Unix socket file. This occurs even if a --port or -P option is given to specify a port number.
这不是典型的tcp/ip连接.如果您具有从127.0.0.1:3306到192.168.1.2:3306的本地端口转发,则"mysql -h localhost"将尝试连接到本地unix套接字文件.
it's not a typical tcp/ip connection. if u have local port forwarding from 127.0.0.1:3306 to 192.168.1.2:3306, "mysql -h localhost" will try to connect to local unix socket file.
这不是特定于您的问题(因为您正在运行php),但希望无论如何它都可以帮助您.
it's not specific to your question(since u're running php), but hope it helps anyway.
这篇关于MySQL localhost/127.0.0.1问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!