mysql正在运行但无法连接到127.0.0.1

时间:2014-10-23 21:53:44

标签: php localhost macports osx-yosemite mysql-5.5

我使用macports安装了mysql55-server。

我可以通过以下方式成功启动服务器:

$ sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql55-server.plist

确认我正在运行正确的mysql:

$ which mysql 

/opt/local/lib/mysql55/bin/mysql

如果我运行$mysql,我可以成功连接。如果我然后运行:

mysql> show databases;

它显示了两个数据库。

使用Sequel Pro,我可以通过socket连接:

u: root
p: root
Socket: /opt/local/var/run/mysql55/mysqld.sock

连接并加载数据库就好了。

问题是通过127.0.0.1或localhost连接。

如果我尝试使用Sequel Pro中的标准连接进行连接,我会得到:

Unable to connect to host 127.0.0.1, or the request timed out.

Be sure that the address is correct and that you have the necessary privileges, or try increasing the connection timeout (currently 10 seconds).

MySQL said: Can't connect to MySQL server on '127.0.0.1' (61)

所以似乎mysql服务器没有被识别为127.0.0.1。在我的hosts文件中,我将本地主机列为127.0.0.1

127.0.0.1   localhost
255.255.255.255 broadcasthost
::1             localhost 
fe80::1%lo0 localhost 

此外,如果我尝试运行:

$ mysql -h 127.0.0.1 -u root

我明白了:

  

ERROR 2003(HY000):无法在' 127.0.0.1'上连接到MySQL服务器(61)

我在小牛队的设置相同,但效果很好。我已经在另一台计算机上更新了Yosemite并遇到了这些问题。我试图交叉检查机器之间的所有设置。这似乎都是对决。为什么localhost,127.0.0.1没有连接,即使服务器正在运行?

更新

Per @Marc B和neverpanic,我改变了my.cnf(/opt/local/etc/mysql55/my.cnf)。我删除了include以从顶部的原始配置文件中提取数据并注释掉skip-networking:

[client]
port                   =  3306
socket                 = /opt/local/var/run/mysql55/mysqld.sock
default-character-set  =  utf8

[mysqld_safe]
socket                 = /opt/local/var/run/mysql55/mysqld.sock
nice                   =  0 
default-character-set  = utf8

[mysqld]
socket                 =  /opt/local/var/run/mysql55/mysqld.sock
port                   = 3306
bind-address           =  127.0.0.1
skip-external-locking
#skip-networking

character-set-server   =  utf8

[mysqldump]
default-character-set  =  utf8

重新启动mysql并且它有效。

1 个答案:

答案 0 :(得分:5)

默认情况下,MacPorts版本的MySQL使用skip-networking设置禁用网络,以允许并行安装多个版本的MySQL(使用套接字时可以使用,但TCP端口无法使用)。

调整MySQL配置文件以启用网络连接。另请参阅port notes mysql55的输出。

相关问题