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

2018-12-31 09:27发布

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.

28条回答
冷夜・残月
2楼-- · 2018-12-31 10:11

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'),
查看更多
旧时光的记忆
3楼-- · 2018-12-31 10:12

I'm running on MAMP Pro and had this similar problem when trying to migrate (create db tables). Tried a few of these mentioned suggestions as well but didn't do it for me.

So, simply (after an hour googling), I added two things to the /config/database.php.

'port' => '1234',
'unix_socket' => '/path/to/my/socket/mysqld.sock'

Works fine now!

查看更多
倾城一夜雪
4楼-- · 2018-12-31 10:14

Mamp user enable option Allow network access to MYSQL

enter image description here

查看更多
零度萤火
5楼-- · 2018-12-31 10:14

I had problems accessing my drupal website and I had a problem exactly like that I fixed it within less than 2 hours. Try on your command line and restart your mysql server or service. Type this when logged in as root or super user, - service mysqld restart

It should work. If it doesn't restart your local webserver, - service httpd restart

That should be enough. Hope it works for other environments too. Cheers.

查看更多
查无此人
6楼-- · 2018-12-31 10:16

In my case, I was running php artisan migrate on my mac terminal, when I needed to ssh into vagrant and run it from there. Hope that helps someone the headache.

查看更多
爱死公子算了
7楼-- · 2018-12-31 10:17

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

查看更多
登录 后发表回答