I just recently replaced my macbook. I setup the previous project I was working on. Unfortunately I encountered this error.
could not find driver (SQL: SHOW FULL TABLES WHERE table_type = 'BASE TABLE')
at vendor/laravel/framework/src/Illuminate/Database/Connection.php:712
708▕ // If an exception occurs when attempting to run a query, we'll format the error
709▕ // message to include the bindings with SQL, which will make this exception a
710▕ // lot more helpful to the developer instead of just the database's errors.
711▕ catch (Exception $e) {
➜ 712▕ throw new QueryException(
713▕ $query, $this->prepareBindings($bindings), $e
714▕ );
715▕ }
716▕ }
I’m using laravel/sail so all services are defined on docker-compose.yml
.
All services are running properly without any errors via command $ sail up -d
.
I can even connect to mysql service using TablePlus App.
Is there any new config I might have missed?
I tried checking DB connection using tinker
and here is the output (no connection error found).
>>> DB::connection();
=> IlluminateDatabaseMySqlConnection {#525}
>>>
3
Answers
I have the same issue using the new Mac (Apple M1 Max), This is how I solve it.
when you run the migration, in the .env file modify the variable DB_HOST pointing to 127.0.0.1, once the migration is finished, put back the service name DB_HOST=mariadb. In my case I am using mariadb.
Hope this help.
It is simple really. Just prefix
artisan
withsail
.With using sail you are using containers and DB_HOST is set to internal host
mysql
which is not defined on host.Also, all other common commands work:
sail artisan migrate
sail php --version
sail composer require some/lib
sail npm run prod
You should use
./vendor/bin/sail
if you don’t have shell alias setup.On Ubuntu 20.04, go to the terminal then type:
Take note of the PHP Version that you are using and replace it on the command as necessary.
Hope it works for you. It did for me.