Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
723 views
in Technique[技术] by (71.8m points)

php - mysql running but cannot connect to 127.0.0.1

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

And confirm I am running the correct mysql:

$ which mysql 

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

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

mysql> show databases;

It shows two databases.

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.

The problem is connecting via 127.0.0.1 or localhost.

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)

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

I get:

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

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?

UPDATE

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

Restarted mysql and it worked.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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).

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...