简体   繁体   中英

Laravel migration could not find driver

I have this error when i try to make php artisan migrate


   Illuminate\Database\QueryException 

  could not find driver (SQL: select * from information_schema.tables where table_schema = lsapp 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(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

I have already create my database on phpmyadmin. here is the configuration of my.env file

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

and here the coonfiguration of mysql in my config/database.php

'mysql' => [
            'driver' => 'mysql',
            'url' => env('DATABASE_URL'),
            'host' => env('DB_HOST', 'localhost'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'lsapp'),
            'username' => env('DB_USERNAME', 'root'),
            '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'),
            ]) : [],
        ]

help me solve that problem

I was able to solve it by executing the following command:

sudo apt-get install -y php7.4-mysql

您可以检查php.ini文件中是否激活了pdo_mysql扩展。

In your php.ini configuration file uncomment the extension, remove ; :

extension=php_pdo_mysql.dll

If you're on Linux make it:

extension=pdo_mysql.so

Then restart the server.

If this isn't working for you, you may need to install pdo_mysql extension into your php library.

It may be that you are using two or more versions of php. So you better do:

sudo apt install php-mysql

This way you can be sure pdo_mysql extension is installed on each version.

After this just restart apache2: sudo systemctl restart apache2 .

I had the same issue with this setup: Laravel, composer, nginx, mariadb, and php8 on Rocky Linux 8. When running php artisan migrate , I got the error that mysql could not find the driver. I installed php-mysql and then everything worked.

sudo dnf install php-mysql -y

or

sudo yum install php-mysql y

then

sudo systemctl restart php-fpm

Good luck and hope this helps.

Failing在此处输入图片说明

Working在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM