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:24

All these answers seem like heavy lifting...

I just created a .env file; edited my bootstrap/app.php file, and uncommented the following line...

Dotenv::load(__DIR__.'/../');

Hope this helps someone

查看更多
皆成旧梦
3楼-- · 2018-12-31 10:26

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.

查看更多
萌妹纸的霸气范
4楼-- · 2018-12-31 10:27

Step 1

Find the path to your unix_socket, to do that just run netstat -ln | grep mysql

You should get something like this

unix  2      [ ACC ]     STREAM     LISTENING     17397    /var/run/mysqld/mysqld.sock

Step 2

Take that and add it in your unix_socket param

'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' <-----
            ),
        ),

Hope it helps !!

查看更多
路过你的时光
5楼-- · 2018-12-31 10:28

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