SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known

前端 未结 16 688
说谎
说谎 2021-01-03 17:56

I download from https://github.com/luciddreamz/laravel Laravel for openshift then upload over my repository over github. This code for connect to database not work. The prob

相关标签:
16条回答
  • 2021-01-03 18:20

    If someone is facing this issue in the hosting services like hostgator or any thing else then you should have to change the value of "localhost" to the relative values which is provided by the hosting provider. In my case it is available in the "phpmyadmin" tab of "cpanel" at the top right corner as "localhost:3302"

    0 讨论(0)
  • 2021-01-03 18:22

    Another reason this can sometimes come up is due to a misconfiguration in your docker-compose (if you're using it) whereby the mysql container is not on the same network that your app servers are on.

    If the network flag is forgotten or incorrect docker won't add the mysql to the DNS for the app server and therefore throw an error like this.

    0 讨论(0)
  • 2021-01-03 18:23

    We're using symfony with doctrine and we are in the process of automating deployment. I got this error when I simply hadn't provided the correct db creds in parameters.yml (I was running doctrine:migrations:migrate)

    This thread has sent me on a bit of a wild goose chase, so I'm leaving this here so others might not have to.

    0 讨论(0)
  • 2021-01-03 18:23

    Just as on FYI to others suddenly experiencing this on an otherwise (previously) working Laravel installation:

    My Laravel environment is on a Ubuntu VirtualBox hosted on a Win-10 laptop.

    I used my phone to share Internet via USB and suddenly started experiencing this issue. I changed to using the phone as wireless hotspot and the issue went away. This is a nameserver/networking issue and is not specific to Laravel or MySQL.

    0 讨论(0)
  • 2021-01-03 18:24

    If someone facing this problem when using Docker, be sure if you are using your version of SQL.

    In my case: MYSQL_VERSION=latest changing to MYSQL_VERSION=5.7.

    Then you need to remove your unused Docker images with docker system prune -a (docs).

    Also, in your .env you need to change DB_HOST=mysql. And run php artisan config:clear.

    I think it will help someone.

    0 讨论(0)
  • 2021-01-03 18:25

    I'm using Laravel with Docker. I solved this problem by changing the value of DB_HOST from localhost to mysql.

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