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

This happened to me because MySQL wasn't running. MySQL was failing to start because I had a missing /usr/local/etc/my.cnf.d/ directory.

This was being required by my /usr/local/etc/my.cnf config file as a glob include (include /usr/local/etc/my.cnf.d/*.cnf).

Running mkdir /usr/local/etc/my.cnf.d, and then starting MySQL, fixed the issue.

查看更多
The star\"
3楼-- · 2020-05-01 09:23

I had the same problem using Docker and MySQL service name db in docker_compose.yml file:

I added the following in the .env file:

DB_HOST=db

you should also assure that your host is discoverable from the php app.

It was because PHP didn't figure out which host to use to connect.

查看更多
够拽才男人
4楼-- · 2020-05-01 09:26

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楼-- · 2020-05-01 09:26

If anyone are still looking for the answer, just check your .env file. For some reason laravel create a .env.example file, so all this answers didn't work for me. I fixed my issue renamming .env.example to .env

查看更多
淡お忘
6楼-- · 2020-05-01 09:27

As of Laravel 5 the database username and password goes in the .env file that exists in the project directory, e.g.

DB_HOST=127.0.0.1
DB_DATABASE=db1
DB_USERNAME=user1
DB_PASSWORD=pass1

As you can see these environment variables are overriding the 'forge' strings here so changing them has no effect:

    'mysql' => [
        'driver'    => 'mysql',
        'host'      => env('DB_HOST', 'localhost'),
        'database'  => env('DB_DATABASE', 'forge'),
        'username'  => env('DB_USERNAME', 'forge'),
        'password'  => env('DB_PASSWORD', ''),
        'charset'   => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix'    => '',
        'strict'    => false,
    ],

More information is here https://mattstauffer.co/blog/laravel-5.0-environment-detection-and-environment-variables

查看更多
Rolldiameter
7楼-- · 2020-05-01 09:27

In my case I had to remove the bootstrap/cache folder and try it again.

My cenario was after a server migration.

查看更多
登录 后发表回答