Laravel msql 配置%db_name% 缓存问题

我正在尝试使用 laravel 配置 msql db,但遇到了一个奇怪的问题。在线搜索后,我仍然没有完成迁移。


在我的 .env 我有


DB_CONNECTION=mysql

DB_HOST=127.0.0.1

DB_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但这没有做任何事情。有人可以帮助我了解发生了什么,谢谢。


胡说叔叔
浏览 167回答 3
3回答

富国沪深

我认为问题出在 DB_PORT 上,它应该是 3306,或者根据服务器设置。更改 DB_PORT,如果所有其他数据都正确,它应该可以工作。

ibeautiful

问题在于 DB_PORT ,如果您使用的是 mamp 服务器,它应该是 3306 或 8000 使其 8889 并且它应该可以工作

千万里不及你

经过一段时间的努力,我设法将 mysql 与应用程序连接起来。.env 没有正确加载,所以之后php artisan config:cache我需要php artisan key:generate我也失踪了DB_PORT。
打开App,查看更多内容
随时随地看视频慕课网APP