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

后端 未结 30 2406
南方客
南方客 2020-11-22 03:23

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

相关标签:
30条回答
  • 2020-11-22 03:48

    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 !!

    0 讨论(0)
  • 2020-11-22 03:49

    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.

    0 讨论(0)
  • 2020-11-22 03:50

    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'),
    
    0 讨论(0)
  • 2020-11-22 03:50

    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

    0 讨论(0)
  • 2020-11-22 03:51

    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'    => '',
        ),
    
    0 讨论(0)
  • 2020-11-22 03:51

    Mamp user enable option Allow network access to MYSQL

    0 讨论(0)
提交回复
热议问题