0

trying to install wordpress on osx mavericks (with built-in apache+php and homebrew mysql).

mysql -u root # connects php -r 'var_dump(mysql_connect("localhost", "root", ""));' # doesn't connect 

web-searching revealed that mysql connects to 'localhost' via a unix socket, but connects to loopback ip 127.0.0.1 via a network socket.

php -r 'var_dump(mysql_connect("127.0.0.1", "root", ""));' # connects! 

why can't i connect to mysql via localhost from php??

2
  • Actually definitely duplicate tbh Commented Aug 15, 2015 at 22:37
  • my bad. i posted an answer to the question this duplicated and i retract this question. Commented Aug 15, 2015 at 23:29

1 Answer 1

0

"web-searching revealed that mysql connects to 'localhost' via a unix socket"

Because PHP is attempting some optimization that is causing unintended effects. Your instance of MySQL is listening for connections on tcp port 3306. PHP is trying to connect to a UNIX socket on the file system.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.