php SQLSTATE[HY000] [1045] 用户“用户名”@“本地主机”的访问被拒绝(使用密码:是)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42496917/
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
SQLSTATE[HY000] [1045] Access denied for user 'username'@'localhost' (using password: YES)
提问by cyber8200
In my Ubuntu VM, I kept getting
在我的 Ubuntu 虚拟机中,我不断得到
SQLSTATE[HY000] [1045] Access denied for user 'username'@'localhost' (using password: YES)
SQLSTATE[HY000] [1045] 用户“用户名”@“本地主机”的访问被拒绝(使用密码:是)
update
更新
I have configured my database like this in my .env file
我已经在我的 .env 文件中像这样配置了我的数据库
DB_HOST=45.55.88.57
DB_DATABASE=b-prod
DB_USERNAME=root
DB_PASSWORD=*********
UNIX_SOCKET=/var/run/mysqld/mysqld.sock
It works perfectly.
它完美地工作。
But when I use
但是当我使用
DB_HOST=45.55.88.57
DB_DATABASE=b-prod
DB_USERNAME=b <----------------------------------------------
DB_PASSWORD=*********
UNIX_SOCKET=/var/run/mysqld/mysqld.sock
I didn't work.
我没有工作。
What else I should look into to prevent this ?
我还应该研究什么来防止这种情况?
I have a feeling that I have the wrong password.
我有一种感觉,我有错误的密码。
How do I test my database password ? DB_PASSWORD=********* ?
如何测试我的数据库密码?DB_PASSWORD=********* ?
This is all user I have
这是我拥有的所有用户
mysql> SELECT User,Host FROM mysql.user;
+------------------+-------------+
| User | Host |
+------------------+-------------+
| root | % |
| root | 127.0.0.1 |
| root | 45.55.88.57 |
| root | ::1 |
| root | b |
| b | localhost |
| debian-sys-maint | localhost |
| root | localhost |
+------------------+-------------+
8 rows in set (0.00 sec)
回答by Jo?o Mantovani
The solution:
解决方案:
Sometimes when you change your .env, the configs don't refresh without clear cache or restarting the server.
有时,当您更改 .env 时,配置不会在没有清除缓存或重新启动服务器的情况下刷新。
The error message are:
错误信息是:
SQLSTATE[HY000] [1045] Access denied for user 'forge'@'localhost' (using password: YES)
The database are trying to get the information from the "cached" .env configuration, you should try:
数据库正在尝试从“缓存的”.env 配置中获取信息,您应该尝试:
php artisan config:clear
php artisan config:clear
if not solve, restart your server.
如果没有解决,请重新启动您的服务器。
[Edit] Another NON RECOMMENDEDoption:
[编辑] 另一个不推荐的选项:
- Go to your
config\database.php
- remove the .env configuration
- 去你的
config\database.php
- 删除 .env 配置
And set your own credentials
并设置您自己的凭据
'mysql' => [
'host' => '45.55.88.77',
'database' => 'prod',
'username' => 'forge',
'password' => '*********',
],
回答by user3161153
This file is caching some data like database configurations \bootstrap\cache\config.php
. Either delete it or update it with new data.
该文件正在缓存一些数据,如数据库配置\bootstrap\cache\config.php
。删除它或用新数据更新它。
回答by Annymosse
I think your problem is with your database and not with laravel.
我认为您的问题在于您的数据库,而不是 Laravel。
mysql> SELECT User,Host FROM mysql.user;
+------------------+-------------+
| User | Host |
+------------------+-------------+
| root | % |
| root | 127.0.0.1 |
| root | 45.55.88.57 |
| root | ::1 |
| root | b |
| b | localhost | <-- must be % not localhost coz you want to access it remotely not locally
| debian-sys-maint | localhost |
| root | localhost |
+------------------+-------------+
8 rows in set (0.00 sec)
Hopefully this can help.
希望这会有所帮助。
回答by Toeur Tenh
check database port if you use wamp, login phpadmin and see Server: MySQLon top of the page.
如果您使用 wamp,请检查数据库端口,登录 phpadmin 并查看页面顶部的服务器:MySQL。