PDOException when trying to run php migrate - php

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.

Related

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

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.

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

Host lookup failed when executing artisan on Laravel

I keep getting this error when trying to execute artisan.
In UdpSocket.php line 47:
socket_sendto(): Host lookup failed [-10001]: Unknown host
The problem seems to be affecting composer as well.
I run Laravel 5.5 on a homestead virtual machine, everything was working as expected until this problem arrived in a very random way.
I really don't know where to start to debug this,
Thanks for the help!

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!

Laravel MySQL database setup error

I want to use a MySQL database with my Laravel 5.2 framework. I'm not able to access phpMyAdmin after I run php artisan serve and open a localhost page.
My .env file :
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_DATABASE=people
DB_USERNAME=pftest
DB_PASSWORD="pftest_2016#9"
After doing this, I ran php artisan migrate and got the following error:
[PDOException] could not find driver
Following which, I have installed the php-mysql extension and checked for its presence in php.ini file.
But I'm still getting the following error :
[PDOException] SQLSTATE[HY000] [2002] Connection refused
So what is the issue and how to solve it?
In the .env file, set
APP_ENV=local
DB_PORT=3306
and then run php artisian migrate --env="local"
Same is valid for dev,production env.

Categories