php - Laravel 5.1 Forge - SQLSTATE[HY000] [1045] 用户 '' @'localhost' 的访问被拒绝(使用密码 : NO))

标签 php laravel

我刚刚在 Laravel 5.1 中构建了我的新应用程序,并且正在尝试将其上线。当我尝试安装 Composer 时,出现此错误。

[PDOException]                                                                     
SQLSTATE[HY000] [1045] Access denied for user ''@'localhost' (using password: NO)  

Script php artisan clear-compiled handling the post-install-cmd event returned with an error

[RuntimeException]  
Error Output:       

我在本地和生产环境中使用环境文件,所以我不知道发生了什么。有什么想法吗?

就像我的环境文件没有在 forge 上被拾取......

配置/datasbase.php

<?php

return [

/*
|--------------------------------------------------------------------------
| PDO Fetch Style
|--------------------------------------------------------------------------
|
| By default, database results will be returned as instances of the PHP
| stdClass object; however, you may desire to retrieve records in an
| array format for simplicity. Here you can tweak the fetch style.
|
*/

'fetch' => PDO::FETCH_CLASS,

/*
|--------------------------------------------------------------------------
| Default Database Connection Name
|--------------------------------------------------------------------------
|
| Here you may specify which of the database connections below you wish
| to use as your default connection for all database work. Of course
| you may use many connections at once using the Database library.
|
*/

'default' => env('DB_CONNECTION', 'mysql'),

/*
|--------------------------------------------------------------------------
| Database Connections
|--------------------------------------------------------------------------
|
| Here are each of the database connections setup for your application.
| Of course, examples of configuring each database platform that is
| supported by Laravel is shown below to make development simple.
|
|
| All database work in Laravel is done through the PHP PDO facilities
| so make sure you have the driver for your particular database of
| choice installed on your machine before you begin development.
|
*/

'connections' => [

    'sqlite' => [
        'driver'   => 'sqlite',
        'database' => storage_path('database.sqlite'),
        'prefix'   => '',
    ],

    '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,
    ],

    'pgsql' => [
        'driver'   => 'pgsql',
        'host'     => env('DB_HOST', 'localhost'),
        'database' => env('DB_DATABASE', 'forge'),
        'username' => env('DB_USERNAME', 'forge'),
        'password' => env('DB_PASSWORD', ''),
        'charset'  => 'utf8',
        'prefix'   => '',
        'schema'   => 'public',
    ],

    'sqlsrv' => [
        'driver'   => 'sqlsrv',
        'host'     => env('DB_HOST', 'localhost'),
        'database' => env('DB_DATABASE', 'forge'),
        'username' => env('DB_USERNAME', 'forge'),
        'password' => env('DB_PASSWORD', ''),
        'charset'  => 'utf8',
        'prefix'   => '',
    ],

],

/*
|--------------------------------------------------------------------------
| Migration Repository Table
|--------------------------------------------------------------------------
|
| This table keeps track of all the migrations that have already run for
| your application. Using this information, we can determine which of
| the migrations on disk haven't actually been run in the database.
|
*/

'migrations' => 'migrations',

/*
|--------------------------------------------------------------------------
| Redis Databases
|--------------------------------------------------------------------------
|
| Redis is an open source, fast, and advanced key-value store that also
| provides a richer set of commands than a typical key-value systems
| such as APC or Memcached. Laravel makes it easy to dig right in.
|
*/

'redis' => [

    'cluster' => false,

    'default' => [
        'host'     => '127.0.0.1',
        'port'     => 6379,
        'database' => 0,
    ],

],

];

最佳答案

发生这种情况的原因是因为 Forge 正在您的项目上运行安装后命令,并且您可能正在访问某个服务提供商中的数据库,因为这可能是您想要附加到 View 的变量,请尝试注释服务提供商中的代码,安装存储库,然后再次推送代码,它应该可以正常工作

关于php - Laravel 5.1 Forge - SQLSTATE[HY000] [1045] 用户 '' @'localhost' 的访问被拒绝(使用密码 : NO)),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33413327/

相关文章:

php - 如何知道哪个变量在 PHP min() 中返回最低值

php - MySQL真正的转义字符串

php - Laravel - 延迟服务提供者如何工作?

javascript - 将正文作为 JSON 传递时,Lumen API 返回 422 错误

php - laravel 处理 OPTION http 方法请求

php - 无法为模块 DBD::Oracle 加载 '/usr/local/lib64/perl5/auto/DBD/Oracle/Oracle.so':libclntsh.so.12.1

php - 如何弃用 PHP 中的函数?

php - 通过链接关联数据库和 PHP

php - Laravel 的中间件顺序(Middleware Priority)。使用 Postgres 的 Multi-Tenancy

php - Laravel 无法将空值插入可为空的数据库字段