访问被拒绝用户'homestead'@'localhost'(使用密码:YES)pdo异常

I got many solution for this problem but none are working.

This is my controller

   <?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Doctor;

 class DoctorController extends Controller
 {
   public function index(){
     $doctors = Doctor::all();
     return $doctors;
     return "this is a doctorController";
   }

  }

and This is my model

    <?php

 namespace App;

 use Illuminate\Database\Eloquent\Model;

class Doctor extends Model
 {
 //
}

and this is my Route.php

 Route::resource("doctor","DoctorController");

This is my .env file

  APP_ENV=local
  APP_DEBUG=true
  APP_KEY=SomeRandomString
  APP_URL=http://localhost

 DB_CONNECTION=mysql
 DB_HOST=localhost
 DB_PORT=3306
 DB_DATABASE=medical
 DB_USERNAME=root
 DB_PASSWORD=

 CACHE_DRIVER=file
 SESSION_DRIVER=file
 QUEUE_DRIVER=sync

 REDIS_HOST=127.0.0.1
 REDIS_PASSWORD=null
 REDIS_PORT=6379

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

I followed the solution of this http://tutsnare.com/access-denied-for-user-homesteadlocalhost-laravel-5/ and Laravel 5.2: PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'homestead'@'localhost' (using password: YES)

but none of them working .what should i do?

php
dphj737575
dphj737575 它可能会帮助其他人:在更新.env文件中的详细信息后,我将清除缓存并重新启动服务器。
接近 4 年之前 回复

3个回答



它的数据库连接错误,表示其密码受到保护。
你不能把它留空(DB_PASSWORD =?)尝试使用'root '如果您之前从未指定过不同的anthing,则为密码。</ p>
</ div>

展开原文

原文

Its database connection error which says its password protected. you can't leave it blank then (DB_PASSWORD=?) try using 'root' as password if you never assigned anthing different before.

dongshuming7131
dongshuming7131 它不是密码问题。我检查了我的config.inc.php文件.passwird字段是空白的。 $ cfg ['Servers'] [$ i] ['user'] ='root'; $ cfg ['Servers'] [$ i] ['password'] ='';
4 年多之前 回复
duanping1920
duanping1920 那么我猜有些密码已经设定好了! 你可能想重置它。 试试这个: - howtoforge.com/setting-changing-resetting-mysql-root-passwords
4 年多之前 回复
duanjuete9206
duanjuete9206 试过,但没有运气。
4 年多之前 回复

If possible provide your config/database.php file. or go to config/database.php file and make changes as :

'mysql' => [
            'driver'    => 'mysql',
            'host'      => env('DB_HOST', 'YOUR_DB_HOST'),
            'database'  => env('DB_DATABASE', 'YOUR_DB_DATABASE'),
            'username'  => env('DB_USERNAME', 'YOUR_DB_USERNAME'),
            'password'  => env('DB_PASSWORD', 'YOUR_DB_PASSWORD'),
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => '',
            'strict'    => false,
        ],
dsa45664
dsa45664 尝试在.env文件中使用DB_PASSWORD = secret
4 年多之前 回复
douli1872
douli1872 还要检查你的mysql服务器是否正在运行:mysqladmin -u homestead -p status输入密码:secret,
4 年多之前 回复
dongliyun3301
dongliyun3301 尝试用127.0.0.1替换localhost,
4 年多之前 回复
dongzheng4556
dongzheng4556 这是默认配置。你不喜欢设置它。你必须改变.env文件。但是无论如何我跟着你的建议。仍然没有工作。
4 年多之前 回复



如果数据库没有密码,请从 .env中删除 DB_PASSWORD = </ code> </ 代码>文件。 看看是否能解决您的问题。</ p>
</ div>

展开原文

原文

If there is no password for the database, remove DB_PASSWORD= from the .env file. See if that solves your issue.

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问