mysql正在运行但无法连接到127.0.0.1 [英] mysql running but cannot connect to 127.0.0.1

查看:1366
本文介绍了mysql正在运行但无法连接到127.0.0.1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用macports安装了mysql55-server.

I have installed mysql55-server using macports.

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

I can start the server successfully via:

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

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

And confirm I am running the correct mysql:

$ which mysql 

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

如果运行$mysql,则可以成功连接.如果我随后运行:

If I run $mysql, I can connect successfully. If I then run:

mysql> show databases;

它显示了两个数据库.

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

Using Sequel Pro, I can connect via socket:

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

连接并加载数据库就可以了.

Connects and loads up the databases just fine.

问题是通过127.0.0.1或localhost连接.

The problem is connecting via 127.0.0.1 or localhost.

如果我尝试通过Sequel Pro中的标准连接来进行连接,则会得到:

If I try to connect using either through standard connection in Sequel Pro, I get:

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

So it seems the mysql server is not identified as 127.0.0.1. In my hosts file I have local host listed as 127.0.0.1

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

另外,如果我尝试运行:

Also if I try to run:

$ mysql -h 127.0.0.1 -u root

我得到:

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

ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (61)

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

I have the same setup on Mavericks which works fine. I have updated to Yosemite on another computer and are experiencing these problems. I have tried to cross check all settings between machines. It all seems to matchup. Why would localhost, 127.0.0.1, not be connecting, even though the server is running?

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

Per @Marc B and neverpanic, I changed my.cnf (/opt/local/etc/mysql55/my.cnf). I removed the include to pull data from the original config file at the top and commented out 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,它起作用了.

Restarted mysql and it worked.

推荐答案

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

MacPorts versions of MySQL disable networking using the skip-networking setting by default to allow side-by-side installation of multiple versions of MySQL (which is possible when using sockets, but impossible with TCP ports).

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

Adjust your MySQL configuration file to enable networking. See also the output of port notes mysql55.

这篇关于mysql正在运行但无法连接到127.0.0.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆