码迷,mamicode.com
首页 > 数据库 > 详细

Laravel [1045] Access denied for user 'homestead'@'localhost' .env没有配置

时间:2018-07-14 11:49:26      阅读:336      评论:0      收藏:0      [点我收藏+]

标签:password   pre   driver   efi   env   app   ret   connect   config   

laravel 连接数据库出现错误  

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

  

1. 确认./config/database.php 

<?php
return [
    ‘default‘ => env(‘DB_CONNECTION‘, ‘mysql‘),
      ‘connections‘ => [

        ‘sqlite‘ => [
            ‘driver‘ => ‘sqlite‘,
            ‘database‘ => env(‘DB_DATABASE‘, database_path(‘database.sqlite‘)),
            ‘prefix‘ => ‘‘,
        ],

        ‘mysql‘ => [
            ‘driver‘ => ‘mysql‘,
            ‘host‘ => env(‘DB_HOST‘, ‘127.0.0.1‘),
            ‘port‘ => env(‘DB_PORT‘, ‘3306‘),
            ‘database‘ => env(‘DB_DATABASE‘, ‘studyonline‘),
            ‘username‘ => env(‘DB_USERNAME‘, ‘root‘),
            ‘password‘ => env(‘DB_PASSWORD‘, ‘‘),
            ‘unix_socket‘ => env(‘DB_SOCKET‘, ‘‘),
            ‘charset‘ => ‘utf8‘,
            ‘collation‘ => ‘utf8_general_ci‘,
            ‘prefix‘ => ‘‘,
            ‘strict‘ => true,
            ‘engine‘ => null,
        ],
        // ...
     ]
]

  

2. 检查.env文件

  默认的配置导致的错误

DB_DATABASE=homestead

DB_USERNAME=homestead

DB_PASSWORD=secret

APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:cdQLOKNt6JfRuIwfABQ/rqDuR42lgFi8qCC5b4R/KsI=
APP_DEBUG=true
APP_URL=http://localhost

LOG_CHANNEL=stack

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=studyonline
DB_USERNAME=root
DB_PASSWORD=

  

3. 重启服务

php artisan cache:clear
php artisan config:clear
php artisan serve

  

cd ./public
php -S localhost:9000

  

laravel artisan 一些命令

* 创建model

php artisan make:model Video

 执行后生成 ./app/Video.php

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Video extends Model
{
    //
}

  

* 创建Controller

php artisan make:controller UserController

 执行后生成  ./app/Http/Controllers/UserController.php

<?php
namespace App\Http\Controllers;

use Illuminate\Http\Request;

class UserController extends Controller {

}

  

Laravel [1045] Access denied for user 'homestead'@'localhost' .env没有配置

标签:password   pre   driver   efi   env   app   ret   connect   config   

原文地址:https://www.cnblogs.com/mingzhanghui/p/9308792.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!