SQLSTATE[HY000] [2002] Connection refused in Laravel 8 - php

Using Laravel 8
Ubuntu 20.04 with Docker
Connect to Database over clients worked perfect. Docker-Container worked.
If I dont start it with php artisan serve it refused the connection to mysql.
With php artisan serve it connects to mysql-docker-container.
I want deploy it. But if I make it like this doc: https://laravel.com/docs/8.x/deployment
it worked fine, but only DB-connection crashes.
I tried: SQLSTATE[HY000] [2002] Connection refused within Laravel homestead
But if I change the Host it answer with this mistake: PDOException: SQLSTATE[HY000] [2002] No such file or directory
need help.

dont forget... WSL :)
use mysql not localhost.

Related

SQLSTATE[HY000] [2002] (trying to connect via (null)) when connecting to digitalocean managed db

I am using digitalocean managed DB in my laravel app . Everything working fine in tinker mode but when using in app it throws
SQLSTATE[HY000] [2002] (trying to connect via (null))
error . even i can connect it from beekeeper studio.
here's my configuration.
DB_CONNECTION=mysql
DB_HOST=obilia-***.db.ondigitalocean.com
DB_PORT=25060
DB_DATABASE=defaultdb
DB_USERNAME=**********
DB_PASSWORD=**********
DB_SSLMODE=required
MYSQL_ATTR_SSL_CA=storage/cert/ca-certificate.crt

php artisan make controller command try connecting to mysql and throwing connection error

when i run any php artisan commands make,key its throwing an error saying
In Connection.php line 664:
SQLSTATE[HY000] [2002] No connection could be made because the
target machine actively refused it. (SQL: select * from system
where key = woocommerce_version limit 1)
In Connector.php line 70:
SQLSTATE[HY000] [2002] No connection could be made because the
target machine actively refused it.
why it tries to connect to mysql database it has nothing to do with it
my server is iis i don't know if its mis-configured, but the same laravel application in localhost shows no error

Error when trying to create doctrine database with phpMyAdmin

I'm a fresh junior php developer and I'm building my first Symfony project.
When I used the command : php bin/console doctrine:database:create
I get these errors :
In AbstractMySQLDriver.php line 93:
An exception occurred in driver: SQLSTATE[HY000] [2002] No such file or directory
In PDOConnection.php line 31:
SQLSTATE[HY000] [2002] No such file or directory
In PDOConnection.php line 27:
SQLSTATE[HY000] [2002] No such file or directory*
I'm actually using MAMP with default config "db_user" and "db_password"
so I edited the .env file with this following code :
DATABASE_URL=mysql://root:root#localhost:8889/mydbname
I know there is something wrong with my host or port, I saw on other topics that some users using MAMP keep Symfony default values for host and port : DATABASE_URL=mysql://root:root#127.0.0.1:3306/mydbname
Thanks for reading me and trying to help me.
I did more searches and some people are saying that localhost syntax is depreciated and prefer using : 127.0.0.1 instead of localhost.
In my case I checked and used Mamp config 'Connect using an UNIX socket'
So it's now working with :
DATABASE_URL=mysql://root:root#127.0.0.1:8889/mydbname

Running Laravel 5 project with DB_HOST=localhost and 127.0.0.1 PDOException

I'm using Laravel 5 on Windows 10, VB, homestead and I am still new, I've just started learning Laravel.
When I run my project in Chrome using DB_HOST=127.0.0.1 in .env file I get this error message:
PDOException in Connector.php line 55:
SQLSTATE[HY000] [2002] Connection refused
and when I change DB_HOST to localhost everything is fine except when I am using tinker (php artisan tinker). I get this message:
PDOException with message 'SQLSTATE[HY000] [2002] No such file or directory'
Database works with DB_HOST=localhost and tinker DB_HOST=127.0.0.1
So, I can't use both at the same time, everytime I must change DB_HOST in .env file from localhost to 127.0.0.1
What can I do to fix this issue?
If you're using Homestead, your DB_HOST should be set to localhost.
The reason why in such case artisan (migrate) cannot connect to database is because you are not executing the commands inside your virtual machine.
To do it the right way connect to your vm using:
vagrant ssh
and once logged in, continue as you'd normally.
Hope that helps!

PDOException when trying to run php migrate

When I tried to run php artisan migrate with laravel, I received the following error: ""
[PDOException] SQLSTATE[HY000] [2002] Connection refused
How do I resolve this issue? I've seen other stackoverflow posts such as Laravel 5 php artisan migrate does not work with similar problems. However, they have a different error message while I have "Connection refused". Any assistance would be greatly appreciated. Thank you!
Make sure sql is running on your computer. Then check the .env file.

Categories