P粉7319775542023-08-11 00:43:41
One of the simplest causes of this error is that the MySQL server is not running. So the first step is to verify. If it's working, continue with other suggestions:
I encountered the exact same problem. None of the above 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".
Not sure why "localhost" doesn't work by default, but I found this answer to a similar problem that was solved in a symfony2 post. https://stackoverflow.com/a/9251924
renew: Some people asked why this fix worked, so I did some research on the issue. As explained in this post, they use different connection types. https://stackoverflow.com/a/9715164
The problem here is that "localhost" uses a UNIX socket and cannot find the database in the standard directory. However, "127.0.0.1" uses TCP (Transmission Control Protocol), which means it runs over the "local network" on your computer and is more reliable than a UNIX socket.
P粉1484347422023-08-11 00:10:06
The error message indicates an attempt to establish a MySQL connection over a socket (which is not supported).
In the context of Laravel (artisan) you may want to use a different/correct environment. For example: php artisan migrate --env=production
(or any other environment). See here.