Skip to content

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

This error message indicates that PHP's MySQLi extension cannot locate the Unix socket file required to connect to the MySQL server. The "No such file or directory" message specifically refers to the missing socket path, not a generic network or credential issue.

This error typically occurs due to:

  • The MySQL server is not running or the socket file was not created.
  • The host parameter is set to localhost, which forces a Unix socket connection, but the expected socket path is missing or misconfigured.
  • The mysqli.default_socket setting in php.ini points to an incorrect location.

You should troubleshoot by:

  • Changing the host from localhost to 127.0.0.1 in your connection string to force a TCP/IP connection:
    php
    $conn = mysqli_connect('127.0.0.1', 'username', 'password', 'database');
  • Verifying the correct socket path using php -i | grep mysqli.default_socket and updating php.ini if necessary.
  • Ensuring the MySQL server is running and the socket file exists at the specified path.

Dual-run preview — compare with live Symfony routes.