SQLSTATE [HY000] [1045]用户'username'@'localhost'的访问被拒绝(使用密码:是) [英] SQLSTATE[HY000] [1045] Access denied for user 'username'@'localhost' (using password: YES)
问题描述
在我的Ubuntu VM中,我不断得到
In my Ubuntu VM, I kept getting
SQLSTATE [HY000] [1045]用户'username'@'localhost'的访问被拒绝(使用密码) :是)
SQLSTATE[HY000] [1045] Access denied for user 'username'@'localhost' (using password: YES)
update
我已经在我的.env文件
update
I have configured my database like this in my .env file
DB_HOST=45.55.88.57
DB_DATABASE=b-prod
DB_USERNAME=root
DB_PASSWORD=*********
UNIX_SOCKET=/var/run/mysqld/mysqld.sock
它工作正常。
但是当我使用
DB_HOST=45.55.88.57
DB_DATABASE=b-prod
DB_USERNAME=b <----------------------------------------------
DB_PASSWORD=*********
UNIX_SOCKET=/var/run/mysqld/mysqld.sock
我没有工作。
我还应该考虑采取什么措施来防止这种情况?
What else I should look into to prevent this ?
我感觉密码输入错误。
如何测试数据库密码? DB_PASSWORD = *********?
How do I test my database password ? DB_PASSWORD=********* ?
这是我拥有的所有用户
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)
推荐答案
解决方案:
有时,更改.env时,如果没有清除缓存或重新启动服务器,配置将不会刷新。
The solution:
Sometimes when you change your .env, the configs don't refresh without clear cache or restarting the server.
错误消息是:
SQLSTATE[HY000] [1045] Access denied for user 'forge'@'localhost' (using password: YES)
尝试从缓存的 .env配置中获取信息,您应该尝试:
The database are trying to get the information from the "cached" .env configuration, you should try:
php artisan config:clear
如果无法解决,请重新启动服务器。
if not solve, restart your server.
- 转到您的
config\database.php
- 删除.env配置
并设置自己的凭据
'mysql' => [
'host' => '45.55.88.77',
'database' => 'prod',
'username' => 'forge',
'password' => '*********',
],
这篇关于SQLSTATE [HY000] [1045]用户'username'@'localhost'的访问被拒绝(使用密码:是)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!