Laravel数据库访问被拒绝 [英] Laravel database access denied

查看:70
本文介绍了Laravel数据库访问被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Laravel的新手,尝试在控制器Article::all()中运行简单命令时遇到错误.错误是:

I am new to Laravel and am getting an error when trying to run a simple command in the controller Article::all(). The error is:

Connector.php第55行中的PDOException: SQLSTATE [HY000] [1045]用户'homestead'@'localhost'的访问被拒绝(使用密码:是)

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

这是我的.env文件:

APP_ENV=local
APP_DEBUG=true
APP_KEY=v1xavEadi4rHv0EGn05zQvtVAtQRA9zo

DB_HOST=localhost
DB_DATABASE=test
DB_USERNAME=root
DB_PASSWORD=

CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync

MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

控制器:

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;

use App\Article;

class ArticlesController extends Controller
{
    public function index() 
    {

        $articles = Article::all();
    }
}

和模型:

namespace App;

use Illuminate\Database\Eloquent\Model;

class Article extends Model
{

    protected $fillable = [

        'name',
        'body'

    ];
}

推荐答案

以后还会有相同的问题的其他人-在Windows中更改环境文件后重新启动命令提示符.重新启动服务器没有用,但是关闭了所有内容,然后再次尝试运行.

Anyone else looking at this in the future with the same issue - restart the command prompt after changing the env file in windows. Restarting the server didn't work, but closing out of everything and then trying it again worked.

这篇关于Laravel数据库访问被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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