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

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

问题描述

我相信我已经成功地将我的(非常基本的)站点部署到了fortrabbit,但是一旦我连接到SSH以运行某些命令(例如php artisan migratephp artisan 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::将app/config/database.php文件中的主机"从"localhost"更改为"127.0.0.1"

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

Laravel 5::将.env文件中的"DB_HOST"从"localhost"更改为"127.0.0.1"

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

我遇到了完全相同的问题.以上解决方案均不适用于我.我通过将/app/config/database.php文件中的主机"从"localhost"更改为"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".

不确定为什么默认情况下"localhost"不起作用,但是我在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(传输控制协议),从本质上讲,它通过计算机上的本地Internet"运行,比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天全站免登陆