php - 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.
现在与应用程序交互php artisan tinker
并检查
Psy Shell v0.9.9 (PHP 7.2.19 — cli) by Justin Hileman
>>> env('DB_USERNAME')
=> null
>>> config('database.connections.mysql.database')
=> "%db_name%"
>>> env('DB_HOST')
=> null
>>> env('DB_USERNAME')
=> null
>>>
所以我不确定发生了什么,我也确实更新了 dbal,composer require doctrine/dbal
但没有做任何事情。有人可以帮我理解发生了什么谢谢。
解决方案
我认为问题出在 DB_PORT 上,它应该是 3306,或者根据服务器设置。更改 DB_PORT,如果所有其他数据都正确,它应该可以工作。
推荐阅读
- python - Python:减少执行时间,优化循环
- ios - 遮罩图像视图 Swift 5
- sql-server - 在分区表上删除和重新创建列存储索引后插入性能下降
- .net - 在 .NET 5 中测试 Azure 函数
- python - 使用两个表作为 keras 的多输出回归的输入,缺失的矩阵乘积
- apache-beam - 在 Python 上使用 Dataflow Beam 读取 CSV 标头并保存
- reactjs - 地理编码反应传单
- java - Hibernate ORA-01792: 表或视图中的最大列数为 1000 - HBM 转换为注释
- c++ - 哪种实现对代码可读性更好?
- rust - 关于 Rust 的函数参数和所有权的一点问题