Vishesh Chanana
Vishesh Chanana

Reputation: 105

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

I am new to Laravel. I am trying to create a laravel CRUD with resource controllers. However, when I try to run php artisan migrate I get the following error:

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

Here is my database.php

 'mysql' => [
        'driver' => 'mysql',
        'host' => env('DB_HOST', '127.0.0.1'),
        'port' => env('DB_PORT', '3306'),
        'database' => env('DB_DATABASE', 'design'),
        'username' => env('DB_USERNAME', 'homestead'),
        'password' => env('DB_PASSWORD', 'secret'),
        'unix_socket' => env('DB_SOCKET', ''),
        'charset' => 'utf8mb4',
        'collation' => 'utf8mb4_unicode_ci',
        'prefix' => '',
        'strict' => true,
        'engine' => null,
    ],

and this is my env file:

    APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:hLJn+XHKPjf5qEvROeyMMLIjw56Kg9RkXhZIlbjjne4=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=design
DB_USERNAME=homestead
DB_PASSWORD=secret

This is a common problem and I have tried many solutions but they wont work. Please help.

Upvotes: 1

Views: 8760

Answers (1)

user8663822
user8663822

Reputation: 267

try to use PORT 3306 and change localhost to 127.0.0.1

for example

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE= 
DB_USERNAME=
DB_PASSWORD=

Upvotes: 1

Related Questions