Laravel 6.4.1 SQLSTATE[HY000] [2002] Connection refused

前端 未结 10 2057
隐瞒了意图╮
隐瞒了意图╮ 2021-02-15 14:32

I am new in Laravel development. I have updated Xampp to 7.3.11 on my Mac Mojave 10.14.6. In Laravel project when I hit php artisan migrate command I got following error.

<
相关标签:
10条回答
  • 2021-02-15 15:09

    I've come across this Error too by building up a new project with Laravel running in docker-compose for development.

    My solution was to compare the prebuild .env-File with the actual credentials I used for building the database container. Especially I was using DB_HOST=127.0.0.1 instead of the correct service name of my docker-compose setup: DB_HOST=mysql

    0 讨论(0)
  • 2021-02-15 15:10

    Open localhost/phpmyadmin and find a tab called User accounts.

    Find the root user and set its password in your .env and also don't forget to create the database named laravel if it doesn't exist

    Then you can clear config cache

    php artisan config:clear
    

    And migrate

    php artisan migrate
    

    Hope this helps

    0 讨论(0)
  • 2021-02-15 15:10

    I had the same issue. It was resolved by just restarting the local host server i.e Xampp

    0 讨论(0)
  • 2021-02-15 15:11

    Damn, I feel so stupid lol. This is what helped me after scratching my head for hours. Check what port your MySQL is running on and that's the one you use in your .env file.

    DB_CONNECTION=mysql
    DB_HOST=127.0.0.1
    DB_PORT=8889
    DB_DATABASE=laravel
    DB_USERNAME=yourusername
    DB_PASSWORD=yourpassword
    

    Make sure when you create your user that you grant all privileges for the user. If you're still confused then ask me and ill find time to help you out. Happy coding everyone!

    0 讨论(0)
  • 2021-02-15 15:17

    I had this issue, I use MAMP for MYSQL server. It was a configuration issue that I solved by changing the port to the correct one I found in MAMP instructions, which is 8889. So the correct configuration in my .env file is:

    DB_CONNECTION=mysql
    DB_HOST=127.0.0.1
    DB_PORT=8889
    DB_DATABASE=dbname
    DB_USERNAME=root
    DB_PASSWORD=rootpassword
    
    0 讨论(0)
  • 2021-02-15 15:20

    Just simple step i follow and solved

    open .env file

    change DB_HOST = 127.0.0.1 to localhost

    done

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