Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

COUPDEGRACES's avatar

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

Hi, i have a problem using php artisan migrate , this problem because when im reInstall php 7.4 im check documentation for using laravel .

    PHP >= 7.3
    BCMath PHP Extension
    Ctype PHP Extension
    Fileinfo PHP extension
    JSON PHP Extension
    Mbstring PHP Extension
    OpenSSL PHP Extension
    PDO PHP Extension
    Tokenizer PHP Extension
    XML PHP Extension

and try install using command

sudo apt install openssl php-common php-curl php-json php-mbstring php-mysql php-xml php-zip

and

sudo apt install php7.4-common php7.4-bcmath openssl php7.4-json php7.4-mbstring

im trying to use command php artisan migrate

so i got error like this

> php artisan migrate

   Illuminate\Database\QueryException 

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

  at vendor/laravel/framework/src/Illuminate/Database/Connection.php:671
    667▕         // If an exception occurs when attempting to run a query, we'll format the error
    668▕         // message to include the bindings with SQL, which will make this exception a
    669▕         // lot more helpful to the developer instead of just the database's errors.
    670▕         catch (Exception $e) {
  ➜ 671▕             throw new QueryException(
    672▕                 $query, $this->prepareBindings($bindings), $e
    673▕             );
    674▕         }
    675▕ 

      +34 vendor frames 
  35  artisan:37
      Illuminate\Foundation\Console\Kernel::handle()
0 likes
24 replies
COUPDEGRACES's avatar

@sinnbeck alreay installed sir

> sudo apt install php7.4-mysql
Reading package lists... Done
Building dependency tree       
Reading state information... Done
php7.4-mysql is already the newest version (7.4.9-2).
php7.4-mysql set to manually installed.
0 upgraded, 0 newly installed, 0 to remove and 32 not upgraded.

im trying to sudo apt upgrade

> sudo apt upgrade
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Calculating upgrade... Done
The following packages have been kept back:
  clang-9 cpp g++ gcc gcc-10-base lib32gcc-s1 lib32stdc++6 libatomic1 libcc1-0
  libclang-common-9-dev libclang-cpp9 libfreefare-bin libfreefare0 libgcc-s1
  libgfortran5 libgomp1 libitm1 libllvm9 liblsan0 libnfc-bin libobjc4
  libquadmath0 libstdc++6 libtsan0 libubsan1 llvm-9 llvm-9-dev llvm-9-runtime
  llvm-9-tools mfcuk mfoc mfterm
0 upgraded, 0 newly installed, 0 to remove and 32 not upgraded.
Sinnbeck's avatar

If you run php -m can you then find pdo_mysql in the list?

1 like
COUPDEGRACES's avatar

@sinnbeck yes sir , this is output php -m

> php -m
[PHP Modules]
bcmath
calendar
Core
ctype
curl
date
dom
exif
FFI
fileinfo
filter
ftp
gd
gettext
hash
iconv
intl
json
libxml
mbstring
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
Phar
posix
readline
Reflection
session
shmop
SimpleXML
soap
sockets
sodium
SPL
standard
sysvmsg
sysvsem
sysvshm
tokenizer
xml
xmlreader
xmlrpc
xmlwriter
xsl
Zend OPcache
zip
zlib

[Zend Modules]
Zend OPcache
Sinnbeck's avatar

Ok. Are you sure you have created a database in mysql? Laravel cannot create a database. It only adds tables to an existing.

COUPDEGRACES's avatar

@sinnbeck for verifcation

im using lampp , and create database with name web

in my env setting

APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:ksA1xSQkHsyTR765SS1j+EQuwY8OoQfgmlVaKvyDPRM=
APP_DEBUG=true
APP_URL=http://localhost

LOG_CHANNEL=stack

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=web
DB_USERNAME=root
DB_PASSWORD=

BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=database
SESSION_LIFETIME=120

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_MAILER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

in DB_HOST im trying to change 127.0.0.1 to localhost or locahlost to 127.0.0.1 , still same error

COUPDEGRACES's avatar

@sinnbeck im trying to make new projek laravel with command laravel new Blog --jet , so i created a database name 'Unidhaand set Env in to same database , trying to php artisan migrate still same error sir

Sinnbeck's avatar

Can you show the mysql config in database.php?

COUPDEGRACES's avatar

yes sir @sinnbeck

database.php

<?php

use Illuminate\Support\Str;

return [

    /*
    |--------------------------------------------------------------------------
    | Default Database Connection Name
    |--------------------------------------------------------------------------
    |
    | Here you may specify which of the database connections below you wish
    | to use as your default connection for all database work. Of course
    | you may use many connections at once using the Database library.
    |
    */

    'default' => env('DB_CONNECTION', 'mysql'),

    /*
    |--------------------------------------------------------------------------
    | Database Connections
    |--------------------------------------------------------------------------
    |
    | Here are each of the database connections setup for your application.
    | Of course, examples of configuring each database platform that is
    | supported by Laravel is shown below to make development simple.
    |
    |
    | All database work in Laravel is done through the PHP PDO facilities
    | so make sure you have the driver for your particular database of
    | choice installed on your machine before you begin development.
    |
    */

    'connections' => [

        'sqlite' => [
            'driver' => 'sqlite',
            'url' => env('DATABASE_URL'),
            'database' => env('DB_DATABASE', database_path('database.sqlite')),
            'prefix' => '',
            'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
        ],

        'mysql' => [
            'driver' => 'mysql',
            'url' => env('DATABASE_URL'),
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'unix_socket' => env('DB_SOCKET', ''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'prefix_indexes' => true,
            'strict' => true,
            'engine' => null,
            'options' => extension_loaded('pdo_mysql') ? array_filter([
                PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
            ]) : [],
        ],

        'pgsql' => [
            'driver' => 'pgsql',
            'url' => env('DATABASE_URL'),
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '5432'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'charset' => 'utf8',
            'prefix' => '',
            'prefix_indexes' => true,
            'schema' => 'public',
            'sslmode' => 'prefer',
        ],

        'sqlsrv' => [
            'driver' => 'sqlsrv',
            'url' => env('DATABASE_URL'),
            'host' => env('DB_HOST', 'localhost'),
            'port' => env('DB_PORT', '1433'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'charset' => 'utf8',
            'prefix' => '',
            'prefix_indexes' => true,
        ],

    ],

    /*
    |--------------------------------------------------------------------------
    | Migration Repository Table
    |--------------------------------------------------------------------------
    |
    | This table keeps track of all the migrations that have already run for
    | your application. Using this information, we can determine which of
    | the migrations on disk haven't actually been run in the database.
    |
    */

    'migrations' => 'migrations',

    /*
    |--------------------------------------------------------------------------
    | Redis Databases
    |--------------------------------------------------------------------------
    |
    | Redis is an open source, fast, and advanced key-value store that also
    | provides a richer body of commands than a typical key-value system
    | such as APC or Memcached. Laravel makes it easy to dig right in.
    |
    */

    'redis' => [

        'client' => env('REDIS_CLIENT', 'phpredis'),

        'options' => [
            'cluster' => env('REDIS_CLUSTER', 'redis'),
            'prefix' => env('REDIS_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_database_'),
        ],

        'default' => [
            'url' => env('REDIS_URL'),
            'host' => env('REDIS_HOST', '127.0.0.1'),
            'password' => env('REDIS_PASSWORD', null),
            'port' => env('REDIS_PORT', '6379'),
            'database' => env('REDIS_DB', '0'),
        ],

        'cache' => [
            'url' => env('REDIS_URL'),
            'host' => env('REDIS_HOST', '127.0.0.1'),
            'password' => env('REDIS_PASSWORD', null),
            'port' => env('REDIS_PORT', '6379'),
            'database' => env('REDIS_CACHE_DB', '1'),
        ],

    ],

];
Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

It all looks good. And I recommend 127.0.0.1 so stick with that. Any chance your config was cached ? php artisan config:clear

9 likes
Sinnbeck's avatar

Oh and curios. How did you add the user to the database ? Can you show it?

COUPDEGRACES's avatar

@sinnbeck , Thanks your for help me sir , like you say And I recommend 127.0.0.1 so stick with that thats solved my problem .

Meshkat's avatar

use

DB_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock

to your .env file.

4 likes
sheerazabbas's avatar

@Meshkat First of all I know it is posted almost 1 year ago.

But second, I just created a new account to this website for liking and giving heart to your answer, it was really helpful.

I want to how you come to know that adding socket thing may resolve the issue.

For me I basically installed a specific version of php individually but was trying to use mysql from MAMP.

And this was just awesome. Thanks.

dhschumann's avatar

For me, changing DB_HOST=localhost to DB_HOST=127.0.0.1 worked

8 likes
saidhr20's avatar

I changed DB_HOST=localhost to DB_HOST=127.0.0.1 it worked

1 like
SajidAlislam's avatar

Here's the thing you can do that can work,

  • go to the phpmyadmin with and check if your database is actually connected or populated by the previous migration
  • change DB_HOST=localhost to DB_HOST=127.0.0.1
  • change the database or create a new database and connect it
1 like
kleytonroan's avatar

It's almost one year ago, but I was this problem know, if you are using Laravel Sail, the DB_HOST must be mysql

DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=producao_management
DB_USERNAME=sail
DB_PASSWORD=sail
vvp3's avatar

let me give you my 2 cents !!

in project 1 (on docker) i had to input something related to socket in my.cnf + 127.0.0.1 as localhost

in project 2 (local) i put localhost instead of the default 127.0.0.1

frustrating for hours ... but thats life ..

JonathanAspeling's avatar

I was working with sail and docker and needed to set my DB_HOST to mysql

DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=password

Please or to participate in this conversation.