MySQL localhost / 127.0.0.1 problem

后端 未结 4 460
渐次进展
渐次进展 2020-12-11 23:35

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 li

相关标签:
4条回答
  • 2020-12-11 23:59

    In your my.cnf file, either change your bind-address to localhost or remove the bind-address setting entirely (which will make mysql listen on all IP's).

    The my.cnf file is usually in /etc or /etc/mysql.

    0 讨论(0)
  • 2020-12-12 00:04

    Besides Michael's words,

    there's another link: http://dev.mysql.com/doc/refman/5.1/en/connecting.html, it says:

    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.

    0 讨论(0)
  • 2020-12-12 00:18

    This is what fixed it for me. PHP.INI defaults to a different location than MySQL for the default socket. To fix, just run these two commands to add an alias (no restart needed):

    mkdir /var/mysql
    ln -s /tmp/mysql.sock /var/mysql/mysql.sock
    

    Source

    0 讨论(0)
  • 2020-12-12 00:24

    From here.

    Set the initial password for the root user on localhost.

    SET PASSWORD FOR root@localhost=PASSWORD('new_password'); FLUSH PRIVILEGES;

    0 讨论(0)
提交回复
热议问题