Laravel .env文件返回错误的数据

时间:2021-12-25 08:15:15

I've been trying to get data from my database in laravel 5.7.3, but it seems to be using the wrong database name, username and password as it returns this error:

我一直在尝试从laravel 5.7.3中的数据库中获取数据,但它似乎使用了错误的数据库名称,用户名和密码,因为它返回此错误:

SQLSTATE[HY000] [1045] Access denied for user 'homestead'@'localhost' (using password: YES) (SQL: select * from `tasks`)

My .env file database section is also according to my needs and set like this:

我的.env文件数据库部分也根据我的需要设置如下:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=mrdb
DB_USERNAME=root
DB_PASSWORD=

PS: My app environment is still local. I can also migrate and put in data into database with artisan tinker without issues, but cannot just fetch data from the database.

PS:我的应用环境仍然是本地的。我也可以使用工匠修补器将数据迁移并放入数据库而不会出现问题,但不能只从数据库中获取数据。

The only way it gets to work is to change config/database.php mysql section to my parameters, which I believe it isn't just right.

它的唯一工作方式是将config / database.php mysql部分更改为我的参数,我认为这不正确。

Why is the .env not wanting the change when the database is called?

为什么.env在调用数据库时不想要更改?

2 个解决方案

#1


1  

Laravel uses caching to speed up your sites loading times, one of the things laravel caches is the config files located in the config/ directory. Most of these files do have references to the .env file by using the env() helper function.

Laravel使用缓存加速您的网站加载时间,其中一个laravel缓存是位于config /目录中的配置文件。这些文件中的大多数都通过使用env()辅助函数来引用.env文件。

One can create a config cache by using php artisan config:cache which will then be stored in bootstrap/cache/config.php.

可以使用php artisan config:cache创建配置缓存,然后将其存储在bootstrap / cache / config.php中。

To remove this specific cache you can use php artisan config:clear, to clear all cache use php artisan cache:clear.

要删除此特定缓存,您可以使用php artisan config:clear,清除所有缓存使用php artisan cache:clear。

#2


2  

This is cache issue use these commands

这是缓存问题使用这些命令

php artisan cache:clear
php artisan config:cache

After that delete all cache file ie inside

之后删除所有缓存文件,即内部

storage/framework/views

#1


1  

Laravel uses caching to speed up your sites loading times, one of the things laravel caches is the config files located in the config/ directory. Most of these files do have references to the .env file by using the env() helper function.

Laravel使用缓存加速您的网站加载时间,其中一个laravel缓存是位于config /目录中的配置文件。这些文件中的大多数都通过使用env()辅助函数来引用.env文件。

One can create a config cache by using php artisan config:cache which will then be stored in bootstrap/cache/config.php.

可以使用php artisan config:cache创建配置缓存,然后将其存储在bootstrap / cache / config.php中。

To remove this specific cache you can use php artisan config:clear, to clear all cache use php artisan cache:clear.

要删除此特定缓存,您可以使用php artisan config:clear,清除所有缓存使用php artisan cache:clear。

#2


2  

This is cache issue use these commands

这是缓存问题使用这些命令

php artisan cache:clear
php artisan config:cache

After that delete all cache file ie inside

之后删除所有缓存文件,即内部

storage/framework/views