我正在嘗試使用 laravel 配置 msql db,但遇到了一個奇怪的問題。在線搜索后,我仍然沒有完成遷移。在我的 .env 我有DB_CONNECTION=mysqlDB_HOST=127.0.0.1DB_PORT='%db_port%'DB_DATABASE='forge'DB_USERNAME='root'DB_PASSWORD='password'所以改變.ENV我做了以后php artisan cache:clear,然后 php artisan config:cache,該運行后,php artisan migrate我得到了 Illuminate\Database\QueryException : SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known (SQL: select * from information_schema.tables where table_schema = %db_name% and table_name = migrations) at /Users/p/Documents/Project/hub-family-server/vendor/laravel/framework/src/Illuminate/Database/Connection.php:664 660| // If an exception occurs when attempting to run a query, we'll format the error 661| // message to include the bindings with SQL, which will make this exception a 662| // lot more helpful to the developer instead of just the database's errors. 663| catch (Exception $e) { > 664| throw new QueryException( 665| $query, $this->prepareBindings($bindings), $e 666| ); 667| } 668| Exception trace: 1 Doctrine\DBAL\Driver\PDOException::("SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known") /Users/p/Documents/Project/hub-family-server/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:31 2 PDOException::("PDO::__construct(): php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known") /Users/p/Documents/Project/hub-family-server/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:27 Please use the argument -v to see more details.所以我不再確定發生了什么,我也確實更新了 dbal,composer require doctrine/dbal但這沒有做任何事情。有人可以幫助我了解發生了什么,謝謝。
3 回答

千萬里不及你
TA貢獻1784條經驗 獲得超9個贊
經過一段時間的努力,我設法將 mysql 與應用程序連接起來。
.env 沒有正確加載,所以之后
php artisan config:cache
我需要
php artisan key:generate
我也失蹤了DB_PORT
。
- 3 回答
- 0 關注
- 189 瀏覽
添加回答
舉報
0/150
提交
取消