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

Sumanthjois's avatar

php artisan migrate: Could not find driver

I am getting the following error when trying to run the command php artisan migrate.

Illuminate\Database\QueryException 

  could not find driver (Connection: mysql, SQL: select table_name as `name`, (data_length + index_length) as `size`, table_comment as `comment`, engine as `engine`, table_collation as `collation` from information_schema.tables where table_schema = 'laravel_blog' and table_type = 'BASE TABLE' order by table_name)

  at vendor\laravel\framework\src\Illuminate\Database\Connection.php:822
    818▕                     $this->getName(), $query, $this->prepareBindings($bindings), $e
    819▕                 );
    820▕             }
    821▕
  ➜ 822▕             throw new QueryException(
    823▕                 $this->getName(), $query, $this->prepareBindings($bindings), $e
    824▕             );
    825▕         }
    826▕     }

  1   vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:65
      PDOException::("could not find driver")

  2   vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:65
      PDO::__construct()
1 like
6 replies
LaryAI's avatar
Level 58

The error message you're encountering indicates that PHP can't find the database driver for MySQL. This typically means that the PDO extension for MySQL is not installed or enabled in your PHP configuration. Here's how you can resolve this issue:

  1. Check if PDO and PDO_MySQL are installed: Open your terminal and run the following command to check if PDO and the MySQL driver for PDO are installed:

    php -m | grep PDO
    

    You should see PDO in the list. If you also see pdo_mysql, it means the extension is installed and you might just need to enable it.

  2. Enable PDO_MySQL extension: If the PDO_MySQL extension is not enabled, you will need to do so. The process for enabling the extension varies depending on your operating system and PHP configuration.

    • For Windows:

      • Locate your php.ini file (you can find out where it is by running php --ini).
      • Open php.ini in a text editor.
      • Find the line ;extension=pdo_mysql (it might be slightly different, like ;extension=php_pdo_mysql.dll).
      • Remove the semicolon (;) at the beginning of the line to uncomment it.
      • Save the file and restart your web server.
    • For Linux:

      • Install the extension using your package manager, for example:
        sudo apt-get install php-mysql # For Ubuntu/Debian
        sudo yum install php-mysql # For CentOS/Fedora
        
      • Restart your web server:
        sudo service apache2 restart # For Apache on Ubuntu/Debian
        sudo systemctl restart httpd.service # For Apache on CentOS/Fedora
        sudo service nginx restart # For Nginx
        
  3. Configure your .env file: Make sure your .env file in the root of your Laravel project is configured with the correct database connection settings. It should look something like this:

    DB_CONNECTION=mysql
    DB_HOST=127.0.0.1
    DB_PORT=3306
    DB_DATABASE=laravel_blog
    DB_USERNAME=your_username
    DB_PASSWORD=your_password
    

    Replace your_username and your_password with the actual username and password for your MySQL database.

  4. Clear config cache: Sometimes Laravel caches the configuration and does not pick up changes from the .env file. You can clear the config cache by running the following command:

    php artisan config:clear
    
  5. Run the migration: After ensuring that the PDO_MySQL extension is enabled and your .env file is correctly configured, try running the migration again:

    php artisan migrate
    

If you follow these steps and still encounter issues, there might be additional problems with your PHP installation or Laravel configuration. Double-check all settings and look for any additional error messages that might give you clues about what's going wrong.

2 likes
xjanusx's avatar

@LaryAI On the 1st line it should be php -m | grep pdo as grep without -i is case sensitive. Else, this also worked for me

1 like
vincent15000's avatar

It seems that you are using the mysql driver.

Have you installed a MySQL server on your computer ?

Have you installed the php extensions for MySQL ?

Please or to participate in this conversation.