在 PHP-LARAVEL 中出现错误“用户'homestead'@'localhost'的访问被拒绝”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/46688282/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Getting error "Access denied for user 'homestead'@'localhost'" in PHP-LARAVEL
提问by Pooja Mokariya
I am new to php-laravel. I am learning laravel from this tutorial on laracast:
我是 php-laravel 的新手。我正在从这个关于 laracast 的教程中学习 laravel:
https://laracasts.com/series/laravel-5-from-scratch/episodes/7?autoplay=true
https://laracasts.com/series/laravel-5-from-scratch/episodes/7?autoplay=true
I wrote code like this video but I am getting the following errors for the database, and I do not understand:
我写了类似这个视频的代码,但我收到数据库的以下错误,我不明白:
[Illuminate\Database\QueryException]
SQLSTATE[HY000] [1045] Access denied for user 'homestead'@'localhost' (using password: YES) (SQL: select * from information_schema.tables
where table_schema = homestead and table_name = migrations)[PDOException]
SQLSTATE[HY000] [1045] Access denied for user 'homestead'@'localhost' (using password: YES)
[Illuminate\Database\QueryException]
SQLSTATE[HY000] [1045] 用户 'homestead'@'localhost' 访问被拒绝(使用密码:YES)(SQL:选择 * from information_schema.tables
where table_schema = homestead and table_name = migrations)[PDOException]
SQLSTATE[HY000] [1045] 用户 'homestead'@'localhost' 访问被拒绝(使用密码:YES)
Does anyone have any idea how to solve it?
有谁知道如何解决它?
回答by pseudoanime
Do you have a .env file? If so, you have to edit the following values:
你有 .env 文件吗?如果是这样,您必须编辑以下值:
DB_HOST=127.0.0.1 //where your database hosted
DB_DATABASE=databasename //this database has to be created manually
DB_USERNAME=username //the username used to access your databases
DB_PASSWORD=password //the password
If you are running it on a vagrantbox, the username & password is usually root & vagrant by default
如果您在 vagrantbox 上运行它,默认情况下用户名和密码通常是 root & vagrant
回答by pseudoanime
Going off what @pseudoanime stated (need 50 reputation or higher to comment):
违背@pseudoanime 所说的(需要 50 声望或更高才能发表评论):
The error provided is the standard error you get when you try to do your first migration in laravel.
提供的错误是您尝试在 laravel 中进行第一次迁移时得到的标准错误。
Here are the settings that help people getting started
以下是帮助人们入门的设置
DB_HOST=127.0.0.1 //where your database hosted
DB_DATABASE=name_of_the_project //this database may exist if you are using laragon
check your mysql workbench or whatever you are using
along laragon
DB_USERNAME=root //the default superuser of a database
//I took out the password field because by default
//the root user doesn't have a password
Please note this should never be used in a production site, this is just the settings to help you get started using laravel
请注意,这不应在生产站点中使用,这只是帮助您开始使用 laravel 的设置