Title rewritten as: PDOException SQLSTATE error encountered, file or directory not found
P粉183077097
P粉183077097 2023-10-10 15:43:30

I believe I have successfully deployed my (very basic) site to fortrabbit, but once I connect to SSH to run some commands (such as php artisan migrate or php artisan db :seed), I get an error message:

[PDOException]
SQLSTATE[HY000] [2002] No such file or directory

At some point, the migration must have worked because my tables are there - but that doesn't explain why it's not working for me now.

P粉183077097
P粉183077097

reply all(2)
P粉788765679

One of the simplest causes of this error is that the MySQL server is not running. So check first. If it has started, continue with the 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 in a similar problem solved in a symfony2 post. https://stackoverflow.com/a/9251924

renew: Some people asked why this fix works, so I did some research on the topic. As mentioned in this post, they seem to 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 essentially means it runs over the "local internet" on your computer and is much more reliable than a UNIX socket in this case.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!