Laravel [1045] Access denied for user 'homestead'@'localhost' .env没有配置
Posted mingzhanghui
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Laravel [1045] Access denied for user 'homestead'@'localhost' .env没有配置相关的知识,希望对你有一定的参考价值。
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 IlluminateDatabaseEloquentModel; class Video extends Model { // }
* 创建Controller
php artisan make:controller UserController
执行后生成 ./app/Http/Controllers/UserController.php
<?php namespace AppHttpControllers; use IlluminateHttpRequest; class UserController extends Controller { }
以上是关于Laravel [1045] Access denied for user 'homestead'@'localhost' .env没有配置的主要内容,如果未能解决你的问题,请参考以下文章
Laravel [1045] 解决方法 Access denied for user 'homestead'@'localhost'
Laravel:SQLSTATE [28000] [1045] 用户 'homestead'@'localhost' 的访问被拒绝
ERROR 1045 (28000): Access denied for user ‘root‘@