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??

  • Actually definitely duplicate tbh – Michael Bailey Aug 15 '15 at 22:37
  • my bad. i posted an answer to the question this duplicated and i retract this question. – soliton_zero Aug 15 '15 at 23:29
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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.