PDOException SQLSTATE[HY000] [2002] 没有这样的文件或目录 [英] PDOException SQLSTATE[HY000] [2002] No such file or directory

查看:27
本文介绍了PDOException SQLSTATE[HY000] [2002] 没有这样的文件或目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我相信我已经成功地将我的(非常基本的)站点部署到了 fortrabbit,但是一旦我连接到 SSH 以运行一些命令(例如 php artisan migratephpartisan db:seed) 我收到一条错误消息:

I believe that I've successfully deployed my (very basic) site to fortrabbit, but as soon as 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 this doesn't explain why it isn't working for me now.

推荐答案

Laravel 4: 更改主机"在来自localhost"的 app/config/database.php 文件中到127.0.0.1"

Laravel 4: Change "host" in the app/config/database.php file from "localhost" to "127.0.0.1"

Laravel 5+: 更改DB_HOST";在来自localhost"的 .env 文件中到127.0.0.1"

Laravel 5+: Change "DB_HOST" in the .env file from "localhost" to "127.0.0.1"

我遇到了完全相同的问题.以上解决方案都不适合我.我通过更改主机"解决了这个问题.在来自localhost"的/app/config/database.php 文件中到127.0.0.1".

I had 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".

不知道为什么本地主机"默认情况下不起作用,但我在 symfony2 帖子中解决的类似问题中找到了这个答案.https://stackoverflow.com/a/9251924/1231563

Not sure why "localhost" doesn't work by default but I found this answer in a similar question solved in a symfony2 post. https://stackoverflow.com/a/9251924/1231563

更新:有些人问为什么此修复程序有效,因此我对该主题进行了一些研究.好像他们使用不同的连接类型,如这篇文章中所述https://stackoverflow.com/a/9715164/1231563

Update: Some people have asked as to why this fix works so I have done a little bit of research into the topic. It seems as though they use different connection types as explained in this post https://stackoverflow.com/a/9715164/1231563

这里出现的问题是localhost"使用 UNIX 套接字并且在标准目录中找不到数据库.然而,127.0.0.1"使用 TCP(传输控制协议),这实质上意味着它通过本地互联网"运行.在这种情况下,在您的计算机上比 UNIX 套接字更可靠.

The issue that arose here is that "localhost" uses a UNIX socket and can not find the database in the standard directory. However "127.0.0.1" uses TCP (Transmission Control Protocol), which essentially means it runs through the "local internet" on your computer being much more reliable than the UNIX socket in this case.

这篇关于PDOException SQLSTATE[HY000] [2002] 没有这样的文件或目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆