gpt4 book ai didi

Laravel:用户 'forge' @'localhost' 的访问被拒绝(但应用中没有使用此类用户)

转载 作者:行者123 更新时间:2023-12-03 23:50:45 24 4
gpt4 key购买 nike

我有一个运行良好的 Laravel 应用程序,但由于某些奇怪的原因,日志文件中有很多奇怪的消息:

[2019-10-04 10:24:21] production.ERROR: SQLSTATE[HY000] [1045] Access denied for user 'forge'@'localhost' (using password: NO) {"exception":"[object] (Doctrine\DBAL\Driver\PDOException(code: 1045): SQLSTATE[HY000] [1045] Access d enied for user 'forge'@'localhost' (using password: NO) at /var/www/html/pzw_prod/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:31, PDOException(code: 1045): SQLSTATE[HY000] [1045] Access denied for user 'forge'@'l ocalhost' (using password: NO) at /var/www/html/pzw_prod/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:27)



问题是,我没有使用名为 forge 的用户连接到数据库。我的 .env 使用完全不同的登录。而且,我再说一遍,一切正常:与数据库的通信按预期工作。正在成功读取和写入数据。

那么......为什么在日志文件中出现这条消息?

更新:
config('database')
$ php artisan tinker
Psy Shell v0.9.9 (PHP 7.2.22 — cli) by Justin Hileman
>>> config('database')
=> [
"default" => "mysql",
"connections" => [
"sqlite" => [
"driver" => "sqlite",
"url" => null,
"database" => /* CENSORED */,
"prefix" => "",
"foreign_key_constraints" => true,
],
"mysql" => [
"driver" => "mysql",
"url" => null,
"host" => "127.0.0.1",
"port" => "3306",
"database" => /* CENSORED */,
"username" => "prod_pzw",
"password" => /* CENSORED */,
"unix_socket" => "",
"charset" => "utf8",
"collation" => "utf8_unicode_ci",
"prefix" => "",
"prefix_indexes" => true,
"strict" => true,
"engine" => null,
"options" => [],
],
"pgsql" => [
"driver" => "pgsql",
"url" => null,
"host" => "127.0.0.1",
"port" => "3306",
"database" => /* CENSORED */,
"username" => "prod_pzw",
"password" => /* CENSORED */,
"charset" => "utf8",
"prefix" => "",
"prefix_indexes" => true,
"schema" => "public",
"sslmode" => "prefer",
],
"sqlsrv" => [
"driver" => "sqlsrv",
"url" => null,
"host" => "127.0.0.1",
"port" => "3306",
"database" => /* CENSORED */,
"username" => "prod_pzw",
"password" => /* CENSORED */,
"charset" => "utf8",
"prefix" => "",
"prefix_indexes" => true,
],
],
"migrations" => "migrations",
"redis" => [
"client" => "predis",
"options" => [
"cluster" => "predis",
"prefix" => /* CENSORED */,
],
"default" => [
"url" => null,
"host" => "127.0.0.1",
"password" => null,
"port" => "6379",
"database" => 0,
],
"cache" => [
"url" => null,
"host" => "127.0.0.1",
"password" => null,
"port" => "6379",
"database" => 1,
],
],
]

更新 2:

似乎“伪造”是某种默认登录。似乎有时 Laravel 没有使用来自 .env 的值。我该如何调试?
$ cat config/database.php | grep -B 5 forge
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
--
'pgsql' => [
'driver' => 'pgsql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '5432'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
--
'sqlsrv' => [
'driver' => 'sqlsrv',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '1433'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),

最佳答案

过去几天我遇到了完全相同的问题,我想我解决了:
.env 中的设置并不总是出于某种原因使用,偶尔 Laravel 只会使用 config/app.phpconfig/database.php 中的默认设置。
config/app.php :

// Change the 'SomeRandomString' to the generated key from your .env
'key' => env('APP_KEY', 'SomeRandomString'),

'cipher' => 'AES-256-CBC',
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,
],

localhostdatabaseusernamepassword.env 更改为您的实际设置。

此示例适用于 MySQL 如果您使用其他数据库引擎,请改为更改为这些变量。

可能有更好的解决方案(更安全?),但这就是迄今为止防止错误出现的原因。

关于Laravel:用户 'forge' @'localhost' 的访问被拒绝(但应用中没有使用此类用户),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58235926/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com