我相信我已经成功地部署了我的(非常基本的)网站到fortrabbit,但只要我连接到SSH运行一些命令(如php artisan migrate或php artisan db:seed),我得到一个错误消息:
[PDOException]
SQLSTATE[HY000] [2002] No such file or directory
在某种程度上,迁移一定是有效的,因为我的表在那里——但这并不能解释为什么它现在不适合我。
我相信我已经成功地部署了我的(非常基本的)网站到fortrabbit,但只要我连接到SSH运行一些命令(如php artisan migrate或php artisan db:seed),我得到一个错误消息:
[PDOException]
SQLSTATE[HY000] [2002] No such file or directory
在某种程度上,迁移一定是有效的,因为我的表在那里——但这并不能解释为什么它现在不适合我。
当前回答
我在MAMP Pro上运行,在尝试迁移(创建db表)时遇到了类似的问题。我也尝试了上面提到的一些建议,但对我来说并不奏效。
因此,简单地(在谷歌了一个小时后),我向/config/database.php添加了两个东西。
'port' => '1234',
'unix_socket' => '/path/to/my/socket/mysqld.sock'
现在工作很好!
其他回答
如果有人还在寻找答案,只要检查你的。env文件。出于某种原因,laravel创建了一个。env。示例文件,所以所有这些答案都不适合我。我修复了重命名。env的问题。.env的示例
我遇到了同样的问题,我运行的是Mac OS X 10.10 Yosemite。我已经启用了操作系统自带的Apache服务器和PHP。然后,我刚刚配置了mCrypt库开始。在那之后,当我使用模型和DB时,我得到了一个错误:
[PDOException]
SQLSTATE[HY000] [2002] No such file or directory
我发现的原因只是因为PHP和MySQL不能自己连接。 为了解决这个问题,我遵循以下步骤:
Open a terminal and connect to the mysql with: mysql -u root -p It will ask you for the related password. Then once you get the mysql promt type the next command: mysql> show variables like '%sock%' You will get something like this: +-----------------------------------------+-----------------+ | Variable_name | Value | +-----------------------------------------+-----------------+ | performance_schema_max_socket_classes | 10 | | performance_schema_max_socket_instances | 322 | | socket | /tmp/mysql.sock | +-----------------------------------------+-----------------+ Keep the value of the last row: /tmp/mysql.sock In your laravel project folder, look for the database.php file there is where you configure the DB connection parameters. In the mysql section add the next line at the end: 'unix_socket' => '/tmp/mysql.sock' You must have something like this: 'mysql' => array( 'driver' => 'mysql', 'host' => 'localhost', 'database' => 'SchoolBoard', 'username' => 'root', 'password' => 'venturaa', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', 'unix_socket' => '/tmp/mysql.sock', ),
现在只需保存更改,并重新加载页面,它必须工作!
步骤1
找到你的unix_socket的路径,只需运行netstat -ln | grep mysql
你应该得到这样的东西
unix 2 [ ACC ] STREAM LISTENING 17397 /var/run/mysqld/mysqld.sock
步骤2
将其添加到unix_socket参数中
'mysql' => array(
'driver' => 'mysql',
'host' => '67.25.71.187',
'database' => 'dbname',
'username' => 'username',
'password' => '***',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'unix_socket' => '/var/run/mysqld/mysqld.sock' <-----
),
),
希望能有所帮助!!
在我的情况下,我没有任何问题,只是忘记启动mysql服务…
sudo service mysqld start
所有现有的答案都是正确的,可能对你有用。 我的情况有点不同。我在本地使用docker-compose up启动一个docker项目时遇到了这个错误。
对于我的特定情况,问题是我从子文件夹运行docker-compose,而不是从docker-compose文件所在的根文件夹运行。
确保从docker-compose所在的文件夹中运行docker-compose。Yml保存到!