Laravel Access被拒绝

时间:2016-03-21 16:31:40

标签: php database laravel laravel-5.1 access-denied

我的laravel应用程序中出现以下错误。 (我正在使用Laravel 5.1)

PDOException in Connector.php line 55:
SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: NO)

详细说明我不解析任何密码:

array('driver' => 'mysql', 'host' => 'localhost', 'database' => 'gen', 'username' => 'root', 'password' => '', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', 'strict' => false, 'name' => 'mysql'), array('0', '2', '0', false, false)) in MySqlConnector.php line 22

我的.env文件在Laravel中看起来像这样:

APP_ENV=local
APP_DEBUG=true
APP_KEY=************************************

DB_HOST=localhost
DB_DATABASE=gen
DB_USERNAME=miad2
DB_PASSWORD=***************

CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync

我使用phpmyadmin并在那里创建了那个用户。

database.php看起来像这样:

<?php

return [

    'fetch' => PDO::FETCH_CLASS,


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

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

    ],


    'migrations' => 'migrations',


    'redis' => [

        'cluster' => false,

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

    ],

];

我在这里呆了几个小时,不知道如何解决这个问题,需要一些帮助。

1 个答案:

答案 0 :(得分:0)

我想通了,所以我现在所做的就是将设置为root的服务器名称和config.inc.php中为空的密码更改为我创建的用户。而且Voila工作了。