PHP: Warning: mysqli_connect(): (HY000/2002): No such file or directory

Warning: mysqli_connect(): (HY000/2002): No such file or directory

This usually happens on customized LAMP installations. Here the php cannot find the corresponding socket to perform this mysqli_connect() function.

In-order to resolve this problem, we need to find out the mysql socket file path by using the following command.

#mysqladmin variables | grep socket

By default the docket path will be "/tmp/mysql. sock".

Then we need to update the socket path in php.ini file.

pdo_mysql.default_socket=/tmp/mysql.sock
mysql.default_socket=/tmp/mysql.sock
mysqli.default_socket = /tmp/mysql.sock

Please note that this value might be different on other systems and need to change accordingly.

After saving the changes, restart the apache web server for reflecting the changes.

That's all…

Leave a Reply