peter's avatar

SQLSTATE[HY000] [2002] No such file or directory

Hi,

I developed a solution on a windows system, I then transfer my files and database to a Mac and at any instance of connecting to the database, I get PDOException "SQLSTATE[HY000] [2002] No such file or directory". I have checked PDO related and can't find anything worthwhile. Any suggestion?

0 likes
4 replies
frezno's avatar
frezno
Best Answer
Level 36

your mysql.sock file isn't found.

You can restart the MySQL server and see, whether this fixes it or you add/edit this line to your php.ini:

pdo_mysql.default_socket="/var/lib/mysql/mysql.sock"

Just check the path to the mysql.sock and adjust it accordingly - and you have to restart Apache after making changes to php.ini

or do the following:

sudo mkdir /var/mysql
cd /var/mysql
sudo ln -s /var/mysql/mysql.sock

i'm not really familiar with MACs so there might be little changes necessary to this

1 like
bashy's avatar

Probably not got MySQL installed/running on the machine (as stated by frezno). Do you use a VM?

milroy's avatar

@peter add port to mysql configuration array

'mysql' => [
      'driver'    => 'mysql',
      'host'      => env('DB_HOST', '127.0.0.1'),
      'port'      => 'XXXX',
      'database'  => env('DB_DATABASE', 'db_name'),
      'username'  => env('DB_USERNAME', 'root'),
      'password'  => env('DB_PASSWORD', 'root'),
      'charset'   => 'utf8',
      'collation' => 'utf8_unicode_ci',
      'prefix'    => '',
      'strict'    => false,
],

NOTE: better to set it in your .env file

peter's avatar

Thanks Frenzy, that was my solution.

Please or to participate in this conversation.