. Advertisement .
..3..
. Advertisement .
..4..
Hi everyone, I’m learning about PHP. While working, I try to run commands PHP artisan migrate or PHP artisan DB: seed. As a result, I get the message:
[PDOException]
SQLSTATE[HY000] [2002] No such file or directory
What can I do about the “sqlstate[hy000] [2002] no such file or directory” issue? Is there a better approach?
The cause:
The “sqlstate[hy000] [2002] no such file or directory” error message shows that a socket connection to MySQL was attempted that is not supported.
Solution: You should likely utilize a different or the proper environment while working with Laravel (artisan).
For example:
The exact same problem was mine. None of these solutions worked for me. I solved the problem by changing the “host” in the /app/config/database.php file from “localhost” to “127.0.0.1”.
Although I’m not sure why “localhost”, doesn’t work by default, this was the answer to a similar question that I solved in a post on symfony2. https://ittutoria.net/a/9251924/1231563
Update: A few people have asked me why this fix works. I did some research on the subject. It seems as though they use different connection types as explained in this post https://ittutoria.net/a/9715164/1231563
Problem is that localhost uses a UNIX socket to find the database in standard directory. TCP (Transmission Control Protocol) is used by “127.0.0.1”, which means that it runs on the “local internet”. This makes your computer more reliable than the UNIX socket.