PDOException SQLSTATE[HY000] [2002] No such file o

2020-05-01 08:42发布

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.

30条回答
放荡不羁爱自由
2楼-- · 2020-05-01 09:10

When using a VirtualMachine make sure you ssh into that machine and navigate to your App folder and call the php artisan migrate command from there.

查看更多
聊天终结者
3楼-- · 2020-05-01 09:12

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

Laravel 5: Change "DB_HOST" in the .env file from "localhost" to "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".

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

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

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.

查看更多
干净又极端
4楼-- · 2020-05-01 09:12

In my case i had no problem at all, just forgot to start the mysql service...

sudo service mysqld start
查看更多
爷、活的狠高调
5楼-- · 2020-05-01 09:12

Check your port carefully . In my case it was 8889 and i am using 8888. change "DB_HOST" from "localhost" to "127.0.0.1" and vice versa

查看更多
何必那么认真
6楼-- · 2020-05-01 09:13

I had similar problems accessing my Drupal website. I fixed it by opening the command line, and restarting my MySQL server or service:

service mysqld restart

This should work. If it doesn't, restart your local webserver:

service httpd restart

That should be enough. Hope it works for other environments, too. Note that these commands generally require superuser privileges.

查看更多
劳资没心,怎么记你
7楼-- · 2020-05-01 09:15

Add mysql.sock path in database.php file like below example

'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'),
查看更多
登录 后发表回答