Laravel 8 – SQLSTATE[HY000] [2002] No such file or directory

  laravel, laravel-sail, mysql, php, web

I’m trying to make a project using Laravel and Sail but I’m getting errors when I’m trying to migrate or do anything related to the project’s database (for example, seeding).

More specifically, when using artisan sail migrate or anything related, I’m getting the following errors:

When DB_HOST=localhost in my .env file:

SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from information_schema.tables where table_schema = noway and table_name = migrations and table_type = 'BASE TABLE')

When DB_HOST=127.0.0.1 in my .env file:

SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = noway and table_name = migrations and table_type = 'BASE TABLE')

What I’ve tried:

  • changing the DB_HOST to localhost and 127.0.0.1 (most common answer online, no succes)
  • making sure SQL is running
  • clearing cache for sail artisan migrate
  • ./vendor/bin/sail down --rmi all -v to remove all images and volumes
  • changing username and password and putting them between ” or ""

None of the above have been of succes.

Source: Ask PHP

LEAVE A COMMENT