php artisan migrate stops with could not find driver
could not find driver (Connection: mysql, SQL: select * from information_schema.tables ...)Short answer
Laravel talks to the database through a PDO driver, and this error means the PHP that runs artisan has none for your DB_CONNECTION. List the drivers that PHP has, install the matching extension (pdo_mysql for MySQL or MariaDB), and make sure a cached config is not still pointing at an old connection.
Fix it fast
1Find out which cause you have
Ask the PHP that runs artisan which PDO drivers it has, then compare with the connection Laravel is using. The driver for your database must be in the list.
php -r 'print_r(PDO::getAvailableDrivers());' grep '^DB_CONNECTION' .env2Match what you see, then jump to its fix
- 1
The driver list from the first step is empty or has no mysql entry while DB_CONNECTION=mysql or mariadb.The PDO driver extension for your database is not installedFix - 2
Your .env says sqlite, pgsql or sqlsrv but only another PDO driver is loaded.DB_CONNECTION names a driver whose extension you never installedFix - 3
You changed .env but artisan keeps using the previous driver.A cached config still holds the old connectionFix
- 1
What does the error look like?
could not find driver (Connection: mysql, SQL: select * from information_schema.tables ...)
Cause 1 of 3
The PDO driver extension for your database is not installed
1Check
On Linux the PHP packages often leave the database extensions as a separate package. Confirm that pdo_mysql is not loaded.
php -m | grep -i pdo
php -r 'var_dump(extension_loaded("pdo_mysql"));'2Fix
Install the MySQL extension package that matches your PHP build. The PHP manual says the extension libraries may need an additional package on top of PHP. The manual names php-mysql on CentOS and a php5-mysql package on an old Ubuntu, so look up the name for your PHP release; on a source build, configure PHP with --with-pdo-mysql.
# example only: the package name depends on your distribution and PHP release
sudo apt install php-mysql3Verify
The driver list now contains mysql.
php -r 'print_r(PDO::getAvailableDrivers());'Confirmed by php.net
Cause 2 of 3
DB_CONNECTION names a driver whose extension you never installed
1Check
Laravel supports MySQL, MariaDB, PostgreSQL, SQLite and SQL Server. Each one needs its own PHP extension, and the SQL Server connection needs both sqlsrv and pdo_sqlsrv. SQLite is an equally valid setup, so a project set up for it fails on a server that only has the MySQL driver.
grep -E '^DB_(CONNECTION|HOST|DATABASE)' .env
php artisan db:show2Fix
Either set DB_CONNECTION (and the host, database, user and password) to the database you really run, or install the extension for the one you named. For SQLite also create the database file the docs describe.
# .env
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=app
DB_USERNAME=app
DB_PASSWORD=change-me3Verify
Laravel can now open the connection and describe it.
php artisan db:showConfirmed by laravel.com
Cause 3 of 3
A cached config still holds the old connection
1Check
Once config:cache has run, Laravel stops reading .env, so edits there have no effect until the cache is rebuilt.
ls bootstrap/cache/2Fix
Clear the cached files that the optimize command created, then run the migration again.
php artisan optimize:clear
php artisan migrate3Verify
The migration runs against the connection written in .env.
php artisan migrate:statusConfirmed by laravel.com
How do I stop it coming back?
- List PDO::getAvailableDrivers() on every new server before the first deploy.
- Check the command-line PHP and the PHP your web server uses separately; they can be different installs.
- Keep the database settings in .env.example so a new machine starts from the same connection.
- Run config:cache only in deployment, and clear it when you change environment values.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- Spotless LaundryAn on-demand laundry app: Flutter on a Laravel back end, with Firebase for live updates.
- EZ EstimaterConstruction quoting and job tracking for contractors, on a Laravel and Firebase stack.
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
Related fixes
Back end
Laravel insert fails with 'Field user_id doesn't have a default value'
The insert works when the column is removed or made nullable
Error 1364 means Laravel sent an INSERT without a value for a NOT NULL column that has no default, and MySQL strict mode refuses it.
3 causes, each with a fixBack end
Laravel migration cannot drop a column that has a foreign key
Error on rename of '%s' to '%s' (errno: %d - %s)
MySQL refuses to drop a column while a foreign key constraint still uses it.
2 causes, each with a fixBack end
Laravel: distinct() and count() give the total instead of the unique count
select('city')->distinct()->count() ignores the select
Laravel builds the count from the column you pass to count(), not from select().
2 causes, each with a fixBack end
Laravel Eloquent query for a column that is X or NULL
where('column', null) returns no rows
Wrap the pair in a closure: where(function ($q) { $q->where('col', $x)->orWhereNull('col'); }).
3 causes, each with a fixBack end
Laravel insert fails with Invalid datetime format 1292 Incorrect datetime value
SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value
MySQL ran in strict mode and refused a date or time value that it cannot store.
3 causes, each with a fixBack end
php artisan migrate stops because the table already exists
SQLSTATE[42S01]: ... 1050 Table 'users' already exists
migrate tried to create a table the database already has.
2 causes, each with a fix