【发布时间】: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