php – 运行mysql但无法连接到127.0.0.1
作者:互联网
我使用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): Can’t connect to MySQL server on ‘127.0.0.1’ (61)
我在小牛队的设置相同,效果很好.我已经在另一台计算机上更新了Yosemite并遇到了这些问题.我试图交叉检查机器之间的所有设置.这似乎都是对决.为什么localhost,127.0.0.1,即使服务器正在运行,也没有连接?
UPDATE
根据@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,它工作.
解决方法:
默认情况下,MacPorts版本的MySQL使用skip-networking设置禁用网络,允许并行安装多个版本的MySQL(使用套接字时可以使用,但TCP端口不可能).
调整MySQL配置文件以启用网络.另请参见端口注释mysql55的输出.
标签:php,osx-yosemite,localhost,macports,mysql-5-5 来源: https://codeday.me/bug/20190519/1138794.html