My php is compiled with the following configuration on CentOS5.5:

./configure --with-mysql=mysqlnd --with-mysqli=mysqlnd ...

When I try to connecting to MySQL, the following error occurred.

Error

Warning: mysql_connect(): [2002] No such file or directory (trying to 
connect via unix:///tmp/mysql.sock) in Command line code on line 1

Solution

Find out the exact location of mysql.sock, then set the exact path in php.ini as:

mysqli.default_socket=/path/to/mysql.sock
mysql.default_socket=/path/to/mysql.sock
pdo_mysql.default_socket=/path/to/mysql.sock

In my situation, the mysql.sock is located at /var/lib/mysql.

Reference: http://dev.mysql.com/doc/refman/5.5/en/problems-with-mysql-sock.html