I also installed MySQL using the dmg package from mysql.com.
At this point PHP and MySQL seemed to be working fine on my system, each tried separately.
Things went ugly when I tried to call MySQL from within a PHP script. Calling $dbc = mysqli_connect(MSQL_HOST, MYSQL_USER, MYSQL_PASSWD, MYSQL_DB) yielded the HY000/2002 error, complaining about the inability to connect through /var/mysql/mysql.sock.
The docs for mysqli_connect indicate that if the host to connect to is the local host, the system will attempt to use a pipe instead of TCP/IP, perhaps for improved efficiency. So it looks like the /var/mysql/mysql.sock pipe is not present. A netstat -a | grep mysql indicates that that's indeed the case, instead there seems to be a /tmp/mysql.sock pipe on my system.
Nice, all I have to do is make use of that. A quick change to $dbc = mysqli_connect(MSQL_HOST, MYSQL_USER, MYSQL_PASSWD, MYSQL_DB, ini_get("mysqli.default_port"), '/tmp/mysql.sock') makes it work. Good times.
Not this is clearly a thing peculiar to my setup, I'd rather fix my setup instead of changing my code to work around this, especially since I need the code to be generic enough to run on a production server, with a different setup. So I take a look at the output provided by phpinfo. Here I see that
Now my system is good to go, I can connect to MySQL from within PHP simply with $dbc = mysqli_connect(MSQL_HOST, MYSQL_USER, MYSQL_PASSWD, MYSQL_DB).
Note: The same issue may affect connecting through the regular mysql_connect, in which case you'll have to change your