Software⏱️ 2 min read📅 2026-05-30

How to Fix: PDOException SQLSTATE[HY000] [2002] No such file or directory

Error message indicates a problem with the PHP environment or database connection.

Quick Answer: Check if the PHP environment is properly configured and the database credentials are correct.

The error 'PDOException SQLSTATE[HY000] [2002] No such file or directory' is a common issue encountered when connecting to a database through SSH. This occurs when the PHP script cannot find the MySQL socket file, which is required for establishing a connection to the database.

🛑 Root Causes of the Error

  • Insufficient permissions on the MySQL socket file or the database user account.

✅ Best Solutions to Fix It

Method 1: Update MySQL Socket File Permissions

  1. Step 1: Identify the current permissions of the MySQL socket file using the command `ls -l /var/run/mysqld/mysqld.sock`.

Method 2: Update Database User Account Permissions

  1. Step 1: Run the command `mysql -u [username] -p[password] --default-character-set=utf8` to connect to the database and update the user account permissions.

🎯 Final Words

To avoid this issue in the future, ensure that the MySQL socket file and database user account have the correct permissions. Additionally, regularly update your PHP script to use the latest version of the MySQL extension.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions