skip to Main Content

I’m trying to execute the php artisan migrate command to create a table in phpmyadmin

But its showing error of

“could not find driver”

I have made the php artisan serve and it worked

 'mysql' => [
                'driver' => 'mysql',
                'host' => env('DB_HOST', '127.0.0.1'),
                'port' => env('DB_PORT', '3306'),
                'database' => env('DB_DATABASE', 'testdb'),
                'username' => env('DB_USERNAME', 'root'),
                'password' => env('DB_PASSWORD', 'xxxx'),
                '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'),
            ]) : [],
        ],

 DB_CONNECTION=mysql
 DB_HOST=127.0.0.1
 DB_PORT=3306
 DB_DATABASE=testdb
 DB_USERNAME=root
 DB_PASSWORD=xxxx

This is the error showing in the command line:

 IlluminateDatabaseQueryException  : could not find driver 
   (SQL: select * from information_schema.tables where table_schema = 
    testdb and table_name = migrations)

  at C:AppServwwwlaravel2vendorlaravelframeworksrcIlluminateDatabaseConnection.php:664
    660|         // If an exception occurs when attempting to run a query, we'll format the error
    661|         // message to include the bindings with SQL, which will make this exception a
    662|         // lot more helpful to the developer instead of just the database's errors.
    663|         catch (Exception $e) {
  > 664|             throw new QueryException(
    665|                 $query, $this->prepareBindings($bindings), $e
    666|             );
    667|         }
    668|

  Exception trace:

  1   PDOException::("could not find driver")
      C:AppServwwwlaravel2vendorlaravelframeworksrcIlluminateDatabaseConnectorsConnector.php:70

  2   PDO::__construct("mysql:host=127.0.0.1;port=3306;dbname=testdb", "root", "xxxx", [])
      C:AppServwwwlaravel2vendorlaravelframeworksrcIlluminateDatabaseConnectorsConnector.php:70

it’s expected to show “tables created successfully” and also created in phpmyadmin

3

Answers


  1. Make sure the mysql is running on your machine if you’re using homestead mysql port might be 33060 ..

    to clarify if mysql is running open the terminal on mac or linux or command line on windows and write
    mysql -u root
    if you got the error that mean the mysql is not running.

    Login or Signup to reply.
  2. You are missing the php-mysql driver for PHP, you can check it by executing php -i | grep mysql
    If you are missing it you have to install it considering your system type, for example if you were working on a php7.2 system on ubuntu, you should do:
    sudo apt-get install php7.2-mysql

    Login or Signup to reply.
  3. Change in config/database.php file according to this:

    'mysql' => [
                'driver' => 'mysql',
                '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'),
                ]) : [],
            ],
    

    Check here : Link

    Open the .env file and edit it. just set up correct database credentials

    DB_CONNECTION=mysql
    DB_HOST=127.0.0.1
    DB_PORT=3306
    DB_DATABASE=            // Your Database Name
    DB_USERNAME=           // Your Database Username
    DB_PASSWORD=          // Your Database Password, If no password is set then just clear it
    

    After .env edit, must be clear cache: php artisan config:cache

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search