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

前端 未结 16 689
说谎
说谎 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:40

    First line of the error message describes the error type: "PDOException". The next line displays PDO::errorInfo, i.e:

    1. SQLSTATE error code (a five characters alphanumeric identifier defined in the ANSI SQL standard).
    2. Driver-specific error code.
    3. Driver-specific error message.
    • "HY000" is a general server error (see Server Error Codes and Messages in MySQL docs).
    • "2002" is MySQL Client Error Code meaning "Can't connect to local MySQL server through socket" (see (Client Error Codes and Messages in MySQL docs).
    • The driver specific error code and message ("php_network_getaddresses: getaddrinfo failed: Name or service not known") tell you that PDO is not able to resolve the host name.

    The stack trace you attached, line 3, reveals that you did not specify the database connection parameters in the configuration file. The error show up when you test on local, right? You need to update /.env with the actual database connection parameters.

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

    Please try this code:

    npm install
    
    0 讨论(0)
  • 2021-01-03 18:42

    In my case, when laravel generated the .env configuration file, laravel also generated two uncommented "DB_HOST" lines at line 11 and 12, delete the one that says "mysql" and uncomment (if yours it's commented) the other one (the one with the localhost ip 127.0.0.1) and it worked. (In my case).

    Have a great day

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

    Check your DB_HOST on your .env file

    DB_HOST=http://localhost/ --> DB_HOST=localhost
    

    php artisan config:clear it will help you, clear cached config

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