Laravel 5错误SQLSTATE [HY000] [1045]用户'forge'@'localhost'的访问被拒绝(使用密码:NO) [英] Laravel 5 error SQLSTATE[HY000] [1045] Access denied for user 'forge'@'localhost' (using password: NO)

查看:727
本文介绍了Laravel 5错误SQLSTATE [HY000] [1045]用户'forge'@'localhost'的访问被拒绝(使用密码:NO)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有时(大约每20个请求)我会收到此错误.但是下一个(下一秒)相同的请求也可以.我不知道为什么它没有通过第一个.有时我会遇到另一个错误:

Sometimes (about every 20 request) I get this error. But the next (next second), the same request, is fine. I dont know why it failed the first one. Sometimes i can get another error :

未找到受支持的加密器.密码和/或密钥长度无效.

No supported encrypter found. The cipher and / or key length are invalid.

我的.env数据库参数很好.

我已经使用php artisan key:generate

此键在我的.env文件中的APP_KEY键下

This key is in my .env file under a APP_KEY key

我的config/app.php有一个键'key' => env('APP_KEY'), 'cipher' => 'AES-256-CBC'

有人知道如何发生吗?

推荐答案

在过去的几天中,我遇到了完全相同的问题,我想我已经解决了:

I had this exact same problem for the past few days and I think I solved it:

.env中的设置由于某些原因并非总是使用,偶尔Laravel只会使用config/app.php和config/database.php中的默认设置.

The settings in .env are not always used for some reason or other and occasionally Laravel will just use the default settings in config/app.php and config/database.php.

config/app.php:

config/app.php:

'key' => env('APP_KEY', 'SomeRandomString'),

'cipher' => 'AES-256-CBC',

将'SomeRandomString'更改为从您的.env生成的密钥

Change the 'SomeRandomString' to the generated key from your .env

config/database.php

config/database.php

'mysql' => [
        'driver'    => 'mysql',
        'host'      => env('DB_HOST', 'localhost'),
        'database'  => env('DB_DATABASE', 'forge'),
        'username'  => env('DB_USERNAME', 'forge'),
        'password'  => env('DB_PASSWORD', ''),
        'charset'   => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix'    => '',
        'strict'    => false,
    ],

从.env将localhost,数据库,用户名,密码更改为您的实际设置.如果使用其他数据库,则此示例适用于MySQL,请改为更改这些变量.

Change localhost, database, username, password to your actual settings from the .env. This example is for MySQL if you use another database, change those variables instead.

可能有更好的解决方案(更安全吗?),但是到目前为止,这仍使错误不会出现.

There might be a better solution (more secure?) but this is what so far kept the error from showing up.

这篇关于Laravel 5错误SQLSTATE [HY000] [1045]用户'forge'@'localhost'的访问被拒绝(使用密码:NO)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆