【问题标题】:SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: No such host is known. (Laravel 8 migration error) [closed]SQLSTATE[HY000] [2002] php_network_getaddresses:getaddrinfo 失败:不知道这样的主机。 (Laravel 8 迁移错误)[关闭]
【发布时间】:2023-03-24 02:19:02
【问题描述】:

在新安装了 livewire 的新 laravel8 jetstream 之后 当我运行命令 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 = lweb and table_name = migrations and table_type = 'BASE TABLE')

  at C:\xampp\htdocs\liveweb\vendor\laravel\framework\src\Illuminate\Database\Connection.php:678
    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:\xampp\htdocs\liveweb\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70
      PDOException::("PDO::__construct(): php_network_getaddresses: getaddrinfo failed: No such host is known. ")

  2   C:\xampp\htdocs\liveweb\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70
      PDO::__construct("mysql:host=mysql;port=3306;dbname=lweb", "root", "", [])
PS C:\xampp\htdocs\liveweb> 

【问题讨论】:

  • 检查 .env 文件中的 DB_HOST 条目和您正在使用的数据库的 config/database.php,如果数据库服务器是也与网络服务器在同一台机器上运行
  • 你还没有启动apache和mysql
  • PDO::__construct("mysql:host=mysql;port=3306;dbname=lweb", "root", "", []) in the error 表明您在 .env 文件中有 DB_HOST=mysql 无法解析为主机地址 - host 表示托管数据库的服务器的 IP 地址

标签: php mysql laravel jetstream


【解决方案1】:

问题解决 只需删除 DB_HOST=mysql

DB_CONNECTION=mysql
DB_HOST=localhost
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=lweb
DB_USERNAME=root
DB_PASSWORD=
  

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=lweb
DB_USERNAME=root
DB_PASSWORD=

【讨论】:

    猜你喜欢
    • 2014-03-18
    • 2021-03-23
    • 1970-01-01
    • 2021-03-22
    • 2020-03-28
    • 2012-01-02
    • 1970-01-01
    • 2015-07-22
    • 1970-01-01
    相关资源
    最近更新 更多