Brian Caballero
Brian Caballero

Reputation: 21

Laravel Sail: could not find driver (SQL: SHOW FULL TABLES WHERE table_type = 'BASE TABLE') --- Mac

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();
=> Illuminate\Database\MySqlConnection {#525}
>>> 

Upvotes: 2

Views: 3656

Answers (3)

Kenneth Kipchumba
Kenneth Kipchumba

Reputation: 59

On Ubuntu 20.04, go to the terminal then type:

sudo apt update

sudo apt install php8.1-mysql

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.

Upvotes: 1

hrvoj3e
hrvoj3e

Reputation: 2754

It is simple really. Just prefix artisan with sail.

With using sail you are using containers and DB_HOST is set to internal host mysql which is not defined on host.

sail artisan migrate

## instead of: php artisan migrate

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.

Upvotes: 2

Abelardo Asensio
Abelardo Asensio

Reputation: 21

I have the same issue using the new Mac (Apple M1 Max), This is how I solve it.

// docker-compose.yml file

I commented out this line and it worked.

services:
  mariadb:
    # MYSQL_ROOT_HOST: "%"

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.

Upvotes: 2

Related Questions