SQLSTATE[HY000] [2002] php_network_getaddresses:getaddrinfo 失败:不知道这样的主机。 laravel 8 中的错误
SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: No such host is known. Error in laravel 8
当我写 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:\Users\NaimBiswas\Desktop\Laravel\four\crudtwo\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:\Users\NaimBiswas\Desktop\Laravel\four\crudtwo\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.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
当我写 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:\Users\NaimBiswas\Desktop\Laravel\four\crudtwo\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:\Users\NaimBiswas\Desktop\Laravel\four\crudtwo\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.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