[英]SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: NO) (SQL: select * from `permissions`)
I upload my project on C-panel and set my connection for database in my env file, it was ok for me with the same settings, but now i don't know why it's happening, this is error:我在 C-panel 上上传我的项目并在我的env文件中设置我的数据库连接,使用相同的设置对我来说没问题,但现在我不知道为什么会这样,这是错误:
SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: NO) (SQL: select *
from `permissions`)
And this is my env file settings for database:这是我的数据库env文件设置:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=thermota_db
DB_USERNAME=thermota_user
DB_PASSWORD= { my password }
i don't know this permissions in error, is my permissions_table?我不知道这个权限错误,是我的权限表吗?
and why error for this table?为什么这张表有错误?
Run this command:运行此命令:
php artisan config:cache
You are trying to use a different user that means that your root value is not used.您正在尝试使用其他用户,这意味着您的根值未使用。
You need to cache your env field to use the values in it.您需要缓存 env 字段以使用其中的值。 That goes for every change you make as well.
这也适用于您所做的每一次更改。
Multiple reasons can be the cause.多种原因可能是原因。
Solution解决方案
if ur on online server do the following steps:如果您在在线服务器上执行以下步骤:
1 - locate to : /vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php
2 - add thoes line of code on the begining of this function : createConnection($dsn, array $config, array $options)
3 - code to add : \Artisan::call('config:cache');
4 - refresh ur home page
5 - remove the "\Artisan::call('config:cache');" line code
6 - enjoye ^^
I had the same issue and I couldn't run config:cache
artisan command even with Artisan::call('config:cache');
我遇到了同样的问题,即使使用
Artisan::call('config:cache');
也无法运行config:cache
artisan 命令. .
So I done this and solved my issue:所以我这样做并解决了我的问题:
artisan config:cache
caches all files from /config
into a single array that it stores. artisan config:cache
将/config
中的所有文件缓存到它存储的单个数组中。 It then reads all config variables from that array and ignores anything in .env
or the /config
files until you recach them.然后它从该数组中读取所有配置变量,并忽略
.env
或/config
文件中的任何内容,直到您重新获取它们。 That's why it still works after deleting .env
.这就是为什么在删除
.env
后它仍然有效的原因。
https://laravel.com/docs/5.6/configuration#configuration-caching https://laravel.com/docs/5.6/configuration#configuration-caching
If you don't have ssh access to your live server, you'd just need to delete the bootstrap/cache/config.php
file, which is the cache file config:cache
generates.如果您没有 ssh 访问您的实时服务器,您只需要删除
bootstrap/cache/config.php
文件,这是config:cache
生成的缓存文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.