'Error in migration of table in Laravel, though there is no problem in connecting with database

When I am trying to migrate a table in laravel with the command php artisan migrate --path="2022_04_17_161039_create_cruds_table.php", I am getting this error -

Illuminate\Database\QueryException 

  could not find driver (SQL: select * from information_schema.tables where table_schema = crud and table_name = migrations and table_type = 'BASE TABLE')

  at vendor/laravel/framework/src/Illuminate/Database/Connection.php:745
    741▕         // If an exception occurs when attempting to run a query, we'll format the error
    742▕         // message to include the bindings with SQL, which will make this exception a
    743▕         // lot more helpful to the developer instead of just the database's errors.
    744▕         catch (Exception $e) {
  ➜ 745▕             throw new QueryException(
    746▕                 $query, $this->prepareBindings($bindings), $e
    747▕             );
    748▕         }
    749▕     }

      +33 vendor frames 
  34  artisan:37
      Illuminate\Foundation\Console\Kernel::handle()

But when I am trying to connect with the database with php artisan db mysql, it's working totally fine.

Please help me, if there is no problem in connecting with the database, then why migration command is not working.

Also, I have enabled the pdo_mysql driver.



Solution 1:[1]

PHP needs to php-mysql extension to communicate with MySQL, make sure to install and have this extension in your system, if you installed it before and you have more than one PHP version, make sure to have this extension for your needed PHP version

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Amir Abouei