Artisan migrate error: Illuminate\Database\QueryException - php

I am trying to migrate and already installed Xampp and also already uncomment the ";extension=php_pdo_mysql.dll" and ";extension=pdo_mysql" in the php.ini file, and still getting that error:
Illuminate\Database\QueryException
could not find driver (SQL: select * from information_schema.tables where table_schema = rav2 and table_name = migrations and table_type = 'BASE TABLE')
PDOException::("could not find driver")
Any ideas?
Thank you!

Maybe, you don't set correct db states at .env.
Check your .env params that you want to connect your database.
for example, table_type = 'BASE TABLE' seems to be wrong?
first, check your php.ini is correct like
# Windows
extension=php_pdo_mysql.dll
# Linux
extension=php_pdo_mysql.so
Is that uncommented ?
if you have ;,remove that.
and you need to restart your xampp after fixing that php.ini.
do /etc/init.d/httpd restart
also your laravel env may be wrong ... so fix .env like:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE= your database name
DB_USERNAME= your database user name
DB_PASSWORD= your database password
and you should check your database config like:
/config/database.php
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'your database name'),
'username' => env('DB_USERNAME', 'your database user name'),
'password' => env('DB_PASSWORD', 'your database password'),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],

Related

Access denied for user 'root'#'pop-os' when running migrations on external host

I'm trying to run laravel migration on another mariadb in the same network (for localhost it works fine). I'm able to access this database using mysql -u root -p 192.168.2.100 just fine.
However using php artisan migrate I get an error
Error message:
SQLSTATE[HY000] [1045] Access denied for user 'root'#'pop-os' (using
password: YES) (SQL: select * from information_schema.tables where
table_schema = 92.168.2.166 and table_name = migrations and table_type
= 'BASE TABLE')
I am running this from pop-os (linux) , but I do not understand why it's using this as a host? I do not have 'pop-os' in my configuration anywhere.
Configuration
ENV File:
DB_CONNECTION=mysql
DB_HOST=192.168.2.100
DB_PORT=3306
DB_DATABASE=Laravel_db
DB_USERNAME=root
DB_PASSWORD=***
database.php (mysql)
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'Laravel_db'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', 'password'),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],
laravel version 9.29.0
Are you sure there is an database user named 'root' with password you are using?
Try to log directly into that database (for example from console) and see if that works.
Also try to give permissions to user 'root':
GRANT ALL PRIVILEGES ON *.* TO 'root'#'ip_address' IDENTIFIED BY 'PASSWORD' WITH GRANT OPTION;

Laravel Mysql setup on ubuntu giving error [1698] on running php aritsan migrate

I installed laravel and setup username and database in mysql.
Then I entered the credentials in database.php file in Laravel project.
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'msn_test1'),
'username' => env('DB_USERNAME', 'msn_user' ),
'password' => env('DB_PASSWORD', 'Passw0rd!'),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],
But when I run:
php artisan migrate
I get this error:
SQLSTATE[HY000] [1698] Access denied for user 'root'#'localhost' (SQL: select * from information_schema.tables where table_schema = laravel and table_name = migrations and table_type = 'BASE TABLE')
I am new to Laravel. Could someone help me with the setup.
The second parameter is the fallback value env('the_env_property_name', 'fallback_variable'), it will fallback if it is not present in the .env file.
You should put these variables in the .env file, create your .env file by copying the .env.example to .env. Set the variables as done below, they are probably already there.
DB_CONNECTION=mysql
DB_USERNAME=msn_user
DB_PASSWORD=Passw0rd!
The .env file is hidden in the project home folder. I found while creating a new one.

Unable to change laravel database

So first thing first i've created migration tables and it successfully migrated and seeded. i've change the .env file
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=jj
DB_USERNAME=root
DB_PASSWORD=
i've tried to change the database.php
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'jj'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],
but i'm still unable to login. the error says SQLSTATE[HY000] [1049] Unknown database 'laravel' (SQL: select * from `users` where `username` = admin limit 1) even though i've migrated and seeded the database
If the configuration looks okay and you are 100% certain that MySQL is running, you might want to clear the configs and caches.
php artisan config:clear
php artisan cache:clear
Try the config one and then the cache if the problem isn't resolved by the first command.
You can read more about the commands here

Cannot run Laravel migration on Homestead

I have been trying to run migration since yesterday but database connection is preventing it
Note: I can access the database very well from other projects. This only happens with laravel on homestead. Here is the output of the php artisan migrate command:
SQLSTATE[HY000] [1045] Access denied for user
'abdellah'#'192.168.10.10' (using password: YES) (SQL: select * from
information_schema.tables where table_schema = furbook and table_name
= migrations and table_type = 'BASE TABLE')
This is my .env database config
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=furbook
DB_USERNAME=abdellah
DB_PASSWORD=bonjour1
And this is the database.php file
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'furbook'),
'username' => env('DB_USERNAME', 'abdellah'),
'password' => env('DB_PASSWORD', 'bonjour1'),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],
I am running on Homestead environment.
Thanks.
Have you made sure everything is spelled correctly?
The only other thing I can think of is adding an extra 0 at the end of the port (DB_PORT=33060).
It's weird but I had a fresh Laravel project using homestead and the only way I could access the DB artisan commands in the terminal was to add a 0 on the port but then I had to take it off again once accessing it through HTTP.
I was able to run the migration successfully by setting the DB username to homestead and DB password to secret.
DB_USERNAME=homestead
DB_PASSWORD=secret

How to fix migrate Laravel error 'PDOException and PDO::__construct'

I'm trying to execute the php artisan migrate command to create a table in phpmyadmin
But its showing error of
"could not find driver"
I have made the php artisan serve and it worked
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'testdb'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', 'xxxx'),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=testdb
DB_USERNAME=root
DB_PASSWORD=xxxx
This is the error showing in the command line:
Illuminate\Database\QueryException : could not find driver
(SQL: select * from information_schema.tables where table_schema =
testdb and table_name = migrations)
at C:\AppServ\www\laravel2\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")
C:\AppServ\www\laravel2\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70
2 PDO::__construct("mysql:host=127.0.0.1;port=3306;dbname=testdb", "root", "xxxx", [])
C:\AppServ\www\laravel2\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70
it's expected to show "tables created successfully" and also created in phpmyadmin
Make sure the mysql is running on your machine if you're using homestead mysql port might be 33060 ..
to clarify if mysql is running open the terminal on mac or linux or command line on windows and write
mysql -u root
if you got the error that mean the mysql is not running.
You are missing the php-mysql driver for PHP, you can check it by executing php -i | grep mysql
If you are missing it you have to install it considering your system type, for example if you were working on a php7.2 system on ubuntu, you should do:
sudo apt-get install php7.2-mysql
Change in config/database.php file according to this:
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],
Check here : Link
Open the .env file and edit it. just set up correct database credentials
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE= // Your Database Name
DB_USERNAME= // Your Database Username
DB_PASSWORD= // Your Database Password, If no password is set then just clear it
After .env edit, must be clear cache: php artisan config:cache

Categories