I am trying to connect laravel application to php myadmin.
When DB_HOST=127.0.0.1 in my .env file
SQLSTATE[HY000] [2002] Connection refused (SQL: select * from `sessions` where `id` = EO901DpTx4qUrgxMniyykEu84HrJGQESns0ySzlx limit 1)
and when DB_HOST=localhost in my .env file
SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from `sessions` where `id` = WYha9n6qWtwN0YcAACdydQSgyHeMc1PcID2Mb6Ns limit 1)
What I’ve tried:
changing the DB_HOST to localhost and 127.0.0.1 (most common
answer online, no succes)
making sure SQL is running
clearing cachefor php artisan config:clear
my .env file is as follows
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=haydar
DB_USERNAME=root
DB_PASSWORD=
my data.php file is as follows
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'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'),
]) : [],
],
Related
I have this project running on Laravel 5.8 and Database on Mysql using XAMPP server.
This is my .env file:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
This is my config/database.php file:
'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' => false,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],
and also created a Database in Xampp named homestead.
this error is showing: SQLSTATE[HY000] [1045] Access denied for user 'user'#'localhost' (using password: YES) (SQL: select * from userswhereemail = test#gmail.com
you need to provide db_name, mysql user_name and password in your .env file.
for xampp default username is 'root' and no password.
so update your .env file
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=matkagu_satta
DB_PASSWORD=
i have some issue about connection on laravel into database MySQL like this.
My laravel files and database has been published on hosting.
Illuminate\Database\QueryException.
SQLSTATE[HY000] [2002] No such file or directory (SQL: SELECT * FROM tbl_master_users WHERE identity_number = '12345' AND password ='password')
I tried to looking for some reference to solve this issue, but it's not working on me.
this is .env file : (I tried to change DB_HOST into 127.0.0.1 but it still same)
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=db_users
DB_USERNAME=uname
DB_PASSWORD=password
this is my configuration on database.php file :
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'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' => false,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],
Socket :
I have tried to connect to the DB mysql using php artisan migrate command and gives me this error
Exception trace:
1 PDOException::("SQLSTATE[HY000] [2002] Connection refused")
/Users/hamad/Desktop/web/php/test/vendor/laravel/framework/srcIlluminate/Database/Connectors/Connector.php:70
2 PDO::__construct("mysql:host=127.0.0.1;port=3306;dbname=laravel", "root", "", [])
/Users/hamad/Desktop/web/php/test/vendor/laravel/framework/src/Illuminate/Database/Connectors/.Connector.php:70
my set up in the env file is
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=
and in config /database.php is
'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'),
'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'),
]) : [],
],
I have tried to use localhost instead of 127.0.0.1 but did not work
thanks for your help
I changed from xampp to mamp program and worked fine
I think it is from the localserver and the port number
xampp using 192.168.64.2 as localserver
mamp uses 127.0.0.1 as localserver
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
I am getting the error
SQLSTATE[HY000] [2002] Operation timed out (SQL: select * from users where 1)
from any query I attempt to send to my database.
Running php artisan migrate runs completely fine from command line showing that my settings are correct! Whats going wrong?!
.env:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=vehiclexray
DB_USERNAME=root
DB_PASSWORD=kzurxsxz1
database.php:
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'database'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', 'password'),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' =>
]