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条回答
Fickle 薄情
2楼-- · 2020-05-01 09:17

The answer from @stuyam solved the "No such file or directory" issue for me

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

But then I had a "Connection refused" error. If anyone had the same issue, my solution for this was to update the app/config/local/database.php file so the port is 8889:

'mysql' => array(
        'driver'    => 'mysql',
        'host'      => '127.0.0.1',
        'port'      => '8889',
        'database'  => 'databaseName',
        'username'  => 'root',
        'password'  => 'root',
        'charset'   => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix'    => '',
    ),
查看更多
对你真心纯属浪费
3楼-- · 2020-05-01 09:17

Attempt to connect to localhost:

SQLSTATE[HY000] [2002] No such file or directory

Attempt to connect to 127.0.0.1:

SQLSTATE[HY000] [2002] Connection refused

OK, just comment / remove the following setting from my.cnf (on OS X 10.5: /opt/local/etc/mysqlxx/my.cnf) to obtain:

[mysqld]
# skip-networking

Of course, stop and start MySQL Server.

查看更多
一纸荒年 Trace。
4楼-- · 2020-05-01 09:18

I ran into this problem when running PHPUnit in Elixir/Gulp, and Homestead as my Vagrant enviroment.

In my case I edited the .env file from DB_HOST=localhost to DB_HOST=192.168.10.10 where 192.168.10.10 is the IP of my Vagrant/Homestead host.

查看更多
Melony?
5楼-- · 2020-05-01 09:20

It worked after I change from DB_HOST=localhost to DB_HOST=127.0.0.1 at .env file

查看更多
我欲成王,谁敢阻挡
6楼-- · 2020-05-01 09:20

Building on the answer from @dcarrith ...

Instead of editing the config files, I created an alias in the location that PHP is looking that connects to the real mysql.sock. (source)

Just run these two commands (no restart needed):

mkdir /var/mysql
ln -s /tmp/mysql.sock /var/mysql/mysql.sock
查看更多
Melony?
7楼-- · 2020-05-01 09:21

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!

查看更多
登录 后发表回答