简体   繁体   English

SQLSTATE [HY000] [1045] 用户'root'@'localhost'的访问被拒绝(使用密码:NO)(SQL:select *来自`permissions`)

[英]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.多种原因可能是原因。

  1. This can happen when the server has already been started before updating database details on your.ENV file.当服务器在更新您的 .ENV 文件上的数据库详细信息之前已经启动时,可能会发生这种情况。
  2. It could also be from inputting wrong database authentication details.也可能是输入了错误的数据库身份验证详细信息。

Solution解决方案

  1. Restart the server anytime you update values on your.ENV file.每当您更新 .ENV 文件上的值时重新启动服务器。
  2. Ensure you use the correct authentication details or better still create a new database user.确保您使用正确的身份验证详细信息,或者最好还是创建一个新的数据库用户。

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.

相关问题 SQL: select * from users: SQLSTATE[HY000] [1045] 用户 'root'@'localhost' 访问被拒绝(使用密码:YES) - SQL: select * from users: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) SQLSTATE[HY000] [1045] 用户 'root'@'localhost' 的访问被拒绝(使用密码:YES)(SQL:从 `cats` 中选择 *) - SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) (SQL: select * from `cats`) SQLSTATE[HY000] [1045] 用户 'root'@'localhost' 的访问被拒绝(使用密码:NO)(SQL:select * from `rooms` order by `order_by` asc) - SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: NO) (SQL: select * from `rooms` order by `order_by` asc) SQLSTATE[HY000] [1045] 用户 'homestead'@'localhost' 的访问被拒绝(使用密码:YES)(SQL:从 `table` 中选择 *) - SQLSTATE[HY000] [1045] Access denied for user 'homestead'@'localhost' (using password: YES) (SQL: select * from `table`) SQLSTATE[HY000] [1045] 使用 Mac Os 和 MAMP 拒绝用户 'root'@'localhost' 的访问(使用密码:否) - SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: NO) using Mac Os and MAMP 错误!:SQLSTATE[HY000] [1045] 用户 'root'@'localhost' 访问被拒绝(使用密码:NO) - ERROR!:SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: NO) 未捕获的 PDOException:SQLSTATE[HY000] [1045] 用户“root”@“localhost”的访问被拒绝(使用密码:否) - Uncaught PDOException: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: NO) SQLSTATE [HY000] [1045] 用户'root'@'localhost'的访问被拒绝(使用密码:YES)symfony2 - SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) symfony2 SQLSTATE [HY000] [1045]拒绝用户'root'@'localhost'的访问(使用密码:是)错误 - SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) error occurs “连接错误:SQLSTATE [HY000] [1045]用户'root'@'localhost'的访问被拒绝(使用密码:NO)” - “Connection error: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: NO)”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM