SQLSTATE[HY000] [2002] Connection refused | - laravel

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

Related

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

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"

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 after update XAMPP with PHP 7.2 on mac

Everything worked fine until I update XAMPP with PHP from 7.1 to 7.2. I noticed to access phpmyadmin using this new XAMPP on mac, need port 8080 (http://localhost:8080/phpmyadmin). Is this the problem? I already tried to change DB_HOST from 127.0.0.1 to localhost but nothing works.
Here my .env looks like
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=testing
DB_USERNAME=root
DB_PASSWORD=''

'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

Laravel not connecting to homestead database

I was developing a laravel application locally on Mac connecting to a mysql database. i recently found out about homestead and pulled my app over to Vagrant Homestead. however now im not able to connect to the mysql server on the homestead/box.
Error i recieve:
SQLSTATE[HY000] [1045] Access denied for user 'root'#'localhost' (using password: YES)
I did update my app's .env file
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=eHDatabase
DB_USERNAME=homestead
DB_PASSWORD=secret
I cleared my app's cache
php artisan cache:clear
I updated my /etc/hosts file
27.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
127.0.0.1 laravel.app
and i also removed the old mysql server running on port 3306 on 127.0.0.1.
but still recieve the connection error.
Any help would be great.
Both .env and /config/database.php are looking fine, so try to run this:
php artisan config:cache

Resources