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

后端 未结 30 2529
南方客
南方客 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:52

    If you are using Laravel Homestead, here is settings

    (include Vagrant-Virtual Machine)

    .bash-profile

    alias vm="ssh vagrant@127.0.0.1 -p 2222"
    

    database.php

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

    Terminal

    vm
    
    vagrant@homestead:~/Code/projectFolder  php artisan migrate:install
    
    0 讨论(0)
  • 2020-11-22 03:52

    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.

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

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

    My cenario was after a server migration.

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

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

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

    I had this problems when I was running my application using docker containers.

    The solution was put the name of the MySQL service container I was using in docker_compose.yml on DB_HOST. In my case, it was db :

    DB_HOST=db
    

    Hope it helps.

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

    When using a VirtualMachine make sure you ssh into that machine and navigate to your App folder and call the php artisan migrate command from there.

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