[英]Laravel 5: php artisan migrate issue
I have correctly specified the configuration in database.php file. 我已经在database.php文件中正确指定了配置。
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'laravel5'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', 'abc123'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
when i run this on console 当我在控制台上运行
php artisan migrate
It gives the error Access denied for user 'homestead'@'localhost' (using password: YES)' 它给用户'homestead'@'localhost'(使用密码:是)的访问被拒绝的错误给出
Why is it is giving this error and what is the solution? 为什么会出现此错误,解决方案是什么?
Check the .env
file, You need to specify the database information on .env
file 检查.env
文件,您需要在.env
文件上指定数据库信息
DB_HOST=localhost
DB_DATABASE=laravel5
DB_USERNAME=root
DB_PASSWORD=abc123
In laravel first priority is .env file so that if there is already set a configuration in .env file that will work first,if not found any configuration in .env file then your database.php file will work.In .env file 在laravel中,第一个优先级是.env文件,因此如果已经在.env文件中设置了将首先运行的配置,如果在.env文件中未找到任何配置,则您的database.php文件将起作用。在.env文件中
DB_HOST=localhost
DB_DATABASE=database
DB_USERNAME=root
DB_PASSWORD=password
If you want to use database.php for configuration then you don't need to use env()
function. 如果要使用database.php进行配置,则无需使用env()
函数。 After removing the env()
function the updated code will be 删除env()
函数后,更新后的代码将是
'mysql' => [
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'laravel5',
'username' => 'root',
'password' => 'abc123',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.