在 Laravel 中迁移表时出现“SQLSTATE[HY000] [2002] No such file or directory”错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28335210/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"SQLSTATE[HY000] [2002] No such file or directory" error when migrating table in Laravel
提问by Ken
I am getting the following error when I try to migrate a table in Laravel 5 using the "php artisan migrate" command:
当我尝试使用“php artisan migrate”命令在 Laravel 5 中迁移表时出现以下错误:
'SQLSTATE[HY000] [2002] No such file or directory' in . . . /vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:47
'SQLSTATE[HY000] [2002] 中没有这样的文件或目录'。. . /vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:47
My .env file includes the default settings as follows:
我的 .env 文件包括如下默认设置:
DB_HOST=localhost
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
My database.php file lists mysql as the default database connection, homestead is listed as the database in my homestead.yaml file, and homestead is one of the tables listed when I access mysql and use the show databases;
command.
我的database.php文件将mysql列为默认的数据库连接,homestead在我的homestead.yaml文件中列为数据库,homestead是我访问mysql并使用show databases;
命令时列出的表之一。
Any thoughts about what I might be doing wrong?
关于我可能做错了什么的任何想法?
回答by lucasloo
try 127.0.0.1
instead of localhost
in your .env
file. It works for me :)
尝试127.0.0.1
而不是localhost
在您的.env
文件中。这个对我有用 :)
回答by Walter
Add mysql.sock path in database.php file like below example
在 database.php 文件中添加 mysql.sock 路径,如下例所示
'unix_socket' => '/Applications/MAMP/tmp/mysql/mysql.sock',
Eample
示例
'mysql' => [
'driver' => 'mysql',
'unix_socket' => '/Applications/MAMP/tmp/mysql/mysql.sock',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '8889'),
PDOException SQLSTATE[HY000] [2002] No such file or directory
回答by Noman Ur Rehman
This seems to be an issue with the socket file. Please let me know if this helps Starting with Zend Tutorial - Zend_DB_Adapter throws Exception: "SQLSTATE[HY000] [2002] No such file or directory"
这似乎是套接字文件的问题。请让我知道这是否有助于从 Zend 教程开始 - Zend_DB_Adapter 抛出异常:“SQLSTATE[HY000] [2002] 没有这样的文件或目录”
回答by LivingPhate
Okay, this is might be a special case to me however I had this issue.
好的,这对我来说可能是一个特例,但是我遇到了这个问题。
I moved my files from a Laragon based server to a mamp based server on a different machine. I had this error for days and I only received this error when running php artisan migrate
and not when loading the page. When loading the page i received table not found which is understandable as the table isn't there.
我将我的文件从基于 Laragon 的服务器移动到另一台机器上基于 mamp 的服务器。我有这个错误好几天了,我只在运行php artisan migrate
时收到这个错误,而不是在加载页面时。加载页面时,我收到找不到表,这是可以理解的,因为该表不存在。
After quite some time I just though of running composer update
and then it fixed the error and worked for me. Not sure if this helps anyone but I came back to this post in case it somehow does.
很长一段时间后,我只是想运行composer update
,然后它修复了错误并对我来说有效。不确定这是否对任何人有帮助,但我又回到了这篇文章,以防万一。