Access denied for user 'user'#'localhost' Laravel 5.8 - php

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=

Related

Laravel is not connecting to the php myadmin database

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'),
]) : [],
],

I can't connect to mysql DB connection refused

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

Database Access denied on Laravel in Production

I'm trying to publish my Laravel 5.8 app on production hosting. I've uploaded the files and have made the changes in .env file. But still while accessing my application., it throws error:
Access denied for user 'root'#'127.0.0.1' (using password: NO)
Below is my .env file:
DB_CONNECTION=mysql
DB_HOST= ip
DB_PORT=3306
DB_DATABASE=secret
DB_USERNAME='secret'
DB_PASSWORD='secret'
I have also made changes in database.php:
'users' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', 'secret'),
'port' => env('DB_PORT', '3306'),
'database' => env(‘DB_DATABASE', 'secret'),
'username' => env('DB_USERNAME', 'secret'),
'password' => env('DB_PASSNORD', 'secret'),
'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: :I'IYSQL_ATTR_SSL_CA => env( 'MYSQL_ATTR_SS L_CA' ),
]) : [],
},
Try.
php artisan config:cache
then
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=secret //enter your right databse name
DB_USERNAME=secret //please check your username
DB_PASSWORD=secret //please check your password
or
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=secret //enter your right databse name
DB_USERNAME=root //please check your username
DB_PASSWORD=enter your correct password //please check your password
change your databse.php
'users' => [
'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_PASSNORD', ''),
'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: :I'IYSQL_ATTR_SSL_CA => env( 'MYSQL_ATTR_SS L_CA' ),
]) : [],
},
As a comment suggest, use localhost instead of 127.0.0.1, but also, same error occurs to me and the problem was the Laravel project cache: just use php artisan config:cache to re-cache the files, or just delete all the files inside the bootstrap/cache folder

Laravel - Issues trying to connect project to database

I'm trying to connect laravel to the database, but I'm having issues.
I'm getting these errors:
1 PDOException::("SQLSTATE[HY000] [1045] Access denied for user 'root'#'localhost' (using password: NO)")
C:\Users\andre\Dropbox\College\Project\Rentable\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php : 68
2 PDO::__construct("mysql:host=localhost;port=3308;dbname=rentable", "root", "", [])
C:\Users\andre\Dropbox\College\Project\Rentable\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php : 68
This is my .env file
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3308
DB_DATABASE=rentable
DB_USERNAME=root
DB_PASSWORD=
This is a screenshot of the database on the localhost:
Most likely the default password for local installations is either root , secret or password, try those in your .env
Check your database parameters in config/database.php. You should have something like this
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'database_name'),
'username' => env('DB_USERNAME', 'database_username'),
'password' => env('DB_PASSWORD', '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'),
]) : [],
],

Laravel 5.4.28 gives "SQLSTATE[HY000] [2002] Operation timed out"

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' =>
]

Categories