Php and Mysql error: could not find driver when migrate version
I'm using Ubuntu 20.04 and from my php.ini
I have enabled: extension=php_pdo_mysql.dll
and extension=php_pdo_sqlite.dll
my .env
file is:
DB_CONNECTION=sqlite DB_HOST=127.0.0.1 DB_PORT=3009 DB_DATABASE=database DB_USERNAME=root DB_PASSWORD=pass123
and when I run: php artisan migrate
I get this error: could not find driver
Illuminate\Database\QueryException : could not find driver (SQL: select * from information_schema.tables where table_schema = blog and table_name = migrations)
at /home/morilon/php_proj/blog/vendor/laravel/framework/src/Illuminate/Database/Connection.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")
/home/morilon/php_proj/blog/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:68
2 PDO::__construct("mysql:host=127.0.0.1;port=3306;dbname=blog", "root", "", [])
/home/morilon/php_proj/blog/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:68
Please use the argument -v to see more details.
I'm using PHP 7 and MySql.
How can I resolve this problem?
-
J1
Jose Luis Jun 28 2021
Maybe you have to install more Php-MySql. You can try with the command below:
pkg --get-selections | grep mysql sudo apt-get remove --purge [everything that came up] sudo apt-get autoremove && sudo apt-get autoclean sudo apt-get install mysql-server
I hope it works for you!!
-
V0
Vuong Do Minh Jun 28 2021
The solution ended up being to install the extension, which would also add its own
.ini
file and activate itself on installation.sudo apt-get install -y php7.4-mysql
I hope it work for you!
-
M0
Mahery Andriniaina Razafimanantsoa Jun 28 2021
I FIXED IT, I just need to run this command:
sudo apt-get install php7.1-sqlite3
and then other error:
[Illuminate\Database\QueryException] Database (databaseName) does not exist. (SQL: select * from sqlite_master where type = 'ta ble' and name = migrations) [InvalidArgumentException] Database (databaseName) does not exist.
so in my case, I created the
database.sqlite
file with touchdatabase/database.sqlite
Then in
config/database.php
I changed the'default' => env('DB_CONNECTION', 'sqlite'),
tosqlite
and in
.env
file I just deleted those lines of code:DB_PORT=3309 DB_DATABASE=database DB_USERNAME=root DB_PASSWORD=secret
and finally, everything is working fine.
Migration table created successfully. Migrated: 2021_01_108976_create_cards_table
hope this will help someone.
* Type maximum 2000 characters.
* All comments have to wait approved before display.
* Please polite comment and respect questions and answers of others.