SQLSTATE[HY000][2002]php_network_getaddresses:getaddrinfofailed:没有这样的主机是已知的。Laravel8中的错误

当我编写 php artisan migrate 命令时,我看到了这样的内容:-

SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: No such host is known.  (SQL: select * from information_schema.tables where table_schema = crudtwo and table_name = migrations and table_type = 'BASE TABLE')

    674?         // If an exception occurs when attempting to run a query, we'll format the error
    675?         // message to include the bindings with SQL, which will make this exception a
    676?         // lot more helpful to the developer instead of just the database's errors.
    677?         catch (Exception $e) {
  ? 678?             throw new QueryException(
    679?                 $query, $this->prepareBindings($bindings), $e
    680?             );
    681?         }
    682?

  1   C:UsersNaimBiswasDesktopLaravelfourcrudtwovendorlaravelframeworksrcIlluminateDatabaseConnectorsConnector.php:70
      PDOException::("PDO::__construct(): php_network_getaddresses: getaddrinfo failed: No such host is known. ")

  2   C:UsersNaimBiswasDesktopLaravelfourcrudtwovendorlaravelframeworksrcIlluminateDatabaseConnectorsConnector.php:70
      PDO::__construct("mysql:host=mysql;port=3306;dbname=crudtwo", "root", "", [])

几个小时后,我找到了解决方案。解决方案是从 .env 文件中删除 DB_HOST=mysql 现在我的问题是任何人都可以解释更多关于这个,为什么会出现这个错误,以及为什么它在删除 DB_HOST=mysql 后解决。

回答

错误 PDO::__construct("mysql:host=mysql;port=3306;dbname=crudtwo", "root", "", [])表明您在 .env 文件中有一个错误的条目

.env文件中的 DB_HOST 更改为

//Change
DB_HOST=mysql

//To
DB_HOST=127.0.0.1


以上是SQLSTATE[HY000][2002]php_network_getaddresses:getaddrinfofailed:没有这样的主机是已知的。Laravel8中的错误的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>