SQLSTATE[HY000] [2002] Connection refused. on SELECT * FROM `users` WHERE `email` = xxxx limit 1 - laravel

I have setup an existing laravel github project with docker, everything is working fine.
I am getting a connection refused error when trying to login to my backend.
Th exact error is:
Illuminate\ Database\ QueryException
SQLSTATE[HY000] [2002] Connection refused
SELECT * FROM users WHERE email = xxxx limit 1
My .env is:
APP_NAME=Laravel
APP_ENV=local
APP_DEBUG=true
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE="xxxxx"
DB_USERNAME="xxxxx"
DB_PASSWORD="xxxxx"

Related

Strange behavior with Laravel Sail: after a restart I need to rebuild

Strange behavior with Laravel Sail: after a reboot, I need to rebuild with docker-compose build --no-cache
I verify that the container is active, and other apps like TablePlus connect perfectly, although it is true that it does so through 127.0.0.1 in its configuration
Tests\Console\Commands\Tasks\Api\AnalyzerCallsCommandTest::time_and_astro_event_generate_normal_job
Illuminate\Database\QueryException: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo for mysql failed: nodename nor servname provided, or not known (SQL: SHOW FULL TABLES WHERE table_type = 'BASE TABLE')
my .env.testing
DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=testing
DB_USERNAME=sail
DB_PASSWORD=password
FORWARD_DB_PORT=3306
my .env
DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=sitelight
DB_USERNAME=sail
DB_PASSWORD=password
FORWARD_DB_PORT=3306
With these settings I can access localhost and log in (use database for this action), access MySQL in Tableplus with server 127.0.0.1
On every change run in sail clear all caches and configs.
Workaround
I need to use in every down MacBook run a stop docker, and run sail build --no-cache
Edited at 15/Aut/2022
Workaournd II
After seeing some posts on the internet, y get an ugly solution
$ docker network inspect bridge
...
"Config": [
{
"Subnet": "172.17.0.0/16",
"Gateway": "172.17.0.1"
}
]
If edit my .env.testing
DB_HOST=172.17.0.1
With this workaround works fine.
But after some time (2 o 3 hours of programming and testing) problem persists with **timeout"
Time: 00:30.131, Memory: 36.50 MB
There was 1 error:
1) Tests\Console\Commands\Tasks\Api\AnalyzerCallsCommandTest::just_one_second_before_first_event_for_analyzer_cron_at_sunset_send_normal_job
Illuminate\Database\QueryException: SQLSTATE[HY000] [2002] Operation timed out (SQL: SHOW FULL TABLES WHERE table_type = 'BASE TABLE')
/Users/abkrim/Sites/sitelight/vendor/laravel/framework/src/Illuminate/Database/Connection.php:759
Of course, at this moment I do some checks:
On table plus work fine connection to MySQL docker
On browser any problem with access to MySQL data

SQLSTATE[HY000] [2002] Connection refused |

I'm using MAC OS and I'm new to laravel .. I'm working on laravel using xampp and when i run the command php artisan migrate
I get this error
SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = web and table_name = migrations and table_type = 'BASE TABLE')
my .env
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=web
DB_USERNAME=root
DB_PASSWORD=
I searched and tried most of the ways and it is still not working unfortunately
Try the methods below:
open your .env file and change DB_HOST = 127.0.0.1 to localhost
try restarting your localhost server (xampp)
try downgrading your xampp to a lower version

"SQLSTATE[HY000] [1045] Access denied for user 'root'#'localhost' : Laravel [duplicate]

This question already has answers here:
lavaral 5 ERROR{ (SQLSTATE[HY000] [1045] Access denied for user 'root'#'localhost' (using password: YES)}
(2 answers)
Closed 4 years ago.
I am unable to register a user account in a Laravel project.
Error
SQLSTATE[HY000] [1045] Access denied for user 'root'#'localhost' (using password: YES) (SQL: select count(*) as aggregate from `users` where `email` = xxx#xx.com)
Is there a solution?
Make sure that you update the below values in your .env file:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=your_database_name
DB_USERNAME=root
DB_PASSWORD=
Once updated .env file, stop the server of your project and serve the project again using the php artisan serve command.
You have to make changes in the .env file for the following fields:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE= your database name
DB_USERNAME= your user name
DB_PASSWORD= your password

Connection error with Database in laravel

I am having problem in laravel project connection with database on the live server all credentials are correct in .env and database.php files.
DB_CONNECTION=mysql
DB_HOST=mysql.hostinger.in
DB_PORT=3306
DB_DATABASE=u497405800_new
DB_USERNAME=u497405800_biosp
DB_PASSWORD=bn2OC9IzSop7
ERROR SHOWING:
PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access
denied for user 'u497405800_biosp'#'127.0.0.1' (using password: NO)

'PDOException' with message 'SQLSTATE [HY000] [1045]

i do not know why lately when I try to make a regitro in the database (using laravel), I get this error:
'PDOException' with message 'SQLSTATE [HY000] [1045] Access denied for user' homestead '#' localhost '( using password: YES) '.
.env file:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=pruebas
DB_USERNAME=root
DB_PASSWORD=
in .env file is properly configured. What more could be ??
thanks.
the solution for this error, if everything is properly configured, is to restart the local server, in my case xampp

Resources