我是靠谱客的博主 甜蜜小蝴蝶,这篇文章主要介绍mysql localhost port,MySQL localhost / 127.0.0.1问题,现在分享给大家,希望可以做个参考。

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.

Within PHP, if I have the db server as 127.0.0.1, everything works as well.

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!

解决方案

Besides Michael's words,

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.

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.

it's not specific to your question(since u're running php), but hope it helps anyway.

最后

以上就是甜蜜小蝴蝶最近收集整理的关于mysql localhost port,MySQL localhost / 127.0.0.1问题的全部内容,更多相关mysql内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(118)

评论列表共有 0 条评论

立即
投稿
返回
顶部