6

我已经使用 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,我可以通过套接字连接:

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。在我的主机文件中,我将本地主机列为 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

我得到:

错误 2003 (HY000): 无法连接到“127.0.0.1”上的 MySQL 服务器 (61)

我在 Mavericks 上有相同的设置,效果很好。我已在另一台计算机上更新到 Yosemite,并且遇到了这些问题。我试图交叉检查机器之间的所有设置。这一切似乎都匹配。为什么即使服务器正在运行,localhost 127.0.0.1 也无法连接?

更新

根据@Marc B and neverpanic,我更改了 my.cnf (/opt/local/etc/mysql55/my.cnf)。我删除了包含以从顶部的原始配置文件中提取数据并注释掉跳过网络:

[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,它工作。

4

1 回答 1

6

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

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

于 2014-10-24T07:22:41.617 回答