php Laravel 5 错误 SQLSTATE[HY000] [1045] 用户 'homestead'@'localhost' 访问被拒绝(使用密码:YES)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29362394/
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
Laravel 5 error SQLSTATE[HY000] [1045] Access denied for user 'homestead'@'localhost' (using password: YES)
提问by Ali Rehman
I have installed Laravel 5 successfully and changed MySQL credentials in database.php file in config directory to '
我已经成功安装了 Laravel 5 并将配置目录中 database.php 文件中的 MySQL 凭据更改为 '
mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'wdcollect'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
I don't want to use homestead and I have changed .env file to
我不想使用宅基地,我已将 .env 文件更改为
APP_ENV=local
APP_DEBUG=true
APP_KEY=apLIzEMOgtc5BUxdT9WRLSvAoIIWO87N
DB_HOST=localhost
DB_DATABASE=wdcollect
DB_USERNAME=root
DB_PASSWORD=
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
I don't understand that why it's saying that access denied for 'homestead'@'localhost'
我不明白为什么它说 'homestead'@'localhost' 访问被拒绝
回答by Ali Rehman
It's working now. I had to restart server. Thanks
它现在正在工作。我不得不重新启动服务器。谢谢
回答by umair.ashfr
I was facing the same issue. Everything was fine but in
我面临着同样的问题。一切都很好,但在
bootstrap/cache/config.php
引导程序/缓存/config.php
always had the incomplete password. Upon digging further, realized that the password had '#' character in it and that was getting dropped. As '#' is used to mark a line as a comment.
总是有不完整的密码。进一步挖掘后,意识到密码中有“#”字符,并且正在被删除。因为 '#' 用于将一行标记为注释。
回答by Syed Nazir Hussain
You need to run these two commands
你需要运行这两个命令
php artisan cache:clear
php artisan config:cache
回答by Omid Ahmadyani
if you before use localhost and root your file be cached
如果您之前使用 localhost 和 root 您的文件被缓存
remove /bootstap/cache/config.php
删除/bootstap/cache/config.php
回答by BlackPearl
None of these worked for me when I deployed my website online on shared hosting, below is what I did that worked.
当我在共享主机上在线部署我的网站时,这些都不适合我,下面是我所做的工作。
In the .env
file, I changed
在.env
文件中,我改变了
DB_HOST=127.0.0.1
to
到
DB_HOST=localhost
and viola, it worked well as expected.
和中提琴,它按预期工作得很好。
回答by Y. Joy Ch. Singha
This works to me:
这对我有用:
php artisan config:clear
php artisan cache:clear
php artisan config:cache
Thanks.
谢谢。
回答by Arman H
I Faced Same Problem what i did
我遇到了同样的问题我做了什么
- php artisan cache:clear
- php artisan config:cache
- php工匠缓存:清除
- php工匠配置:缓存
but Same problem found than i run this artisan command
但是发现与我运行此工匠命令相同的问题
php artisan view:clear
php工匠视图:清除
Hope it will helpful.
希望它会有所帮助。
回答by Mauro Lacerda
I had the same problem, so I realized that the .env
file does not accept special characters, as my password has these characters, I added the password in the config/database.php
file.
我有同样的问题,所以我意识到.env
文件不接受特殊字符,因为我的密码有这些字符,我在config/database.php
文件中添加了密码。
回答by Margus Pala
You do not need to set credentials in database.php file. It is enough if you have credentials in .env
您不需要在 database.php 文件中设置凭据。如果您在 .env 中有凭据就足够了
If you are able to login to database directly then this password must work. It can be possible that you are having different environment than "local" which is defined in this file. Test is with "php artisan env"
如果您能够直接登录数据库,那么此密码必须有效。您的环境可能与此文件中定义的“本地”环境不同。测试使用“php artisan env”
回答by Harish Lalwani
Try to checkout the ".env" file in your root directory. It will be a hidden file. Correct these values.
尝试检查根目录中的“.env”文件。这将是一个隐藏文件。更正这些值。
DB_HOST=localhost
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret