访问被拒绝'用户名'@'localhost',如何测试数据库密码?

在UbuntuVM中,我一直收到:

SQLSTATE[HY000] [1045] Access denied for user 'username'@'localhost' (using password: YES)


更新

在.env文件中我已经像这样配置了数据库:

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

却不起作用了。

我还应该调查些什么来防止这件事?


我感觉密码可能错了。

如何测试我的数据库密码?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)

The solution:

Sometimes when you change your .env, the configs don't refresh without clear cache or restarting the server.

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:

php artisan config:clear

if not solve, restart your server.

[Edit] Another NON RECOMMENDED option:

  • Go to your config\database.php
  • remove the .env configuration

And set your own credentials

'mysql' => [
            'host' => '45.55.88.77',
            'database' => 'prod',
            'username' => 'forge',
            'password' => '*********',
        ],

This file is caching some data like database configurations \bootstrap\cache\config.php. Either delete it or update it with new data.