用户“homestead”@“localhost”被拒绝访问QueryException SQLSTATE[HY000][1045](使用密码:YES)

时间:2021-07-01 19:19:17

Why is the following error occurring?

为什么会发生以下错误?

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

用户“homestead”@“localhost”被拒绝访问QueryException SQLSTATE[HY000][1045](使用密码:YES)

My .env file is as follows:

我的。env档案如下:

APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:P7auDP3AGgfkYLPbu+2/m7RCLc42Sip/HuXLLQFZiYs=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=student_management
DB_USERNAME=root
DB_PASSWORD=

5 个解决方案

#1


4  

@Tazwar Utshas

@Tazwar Utshas

You should clear the cache after changing in .env file

在.env文件中修改后,应该清除缓存

run the following commands

运行以下命令

php artisan cache:clear 
php artisan config:clear 
php artisan config:cache  

#2


1  

It's either you edit a wrong file or you have not saved the .env yet. Because in your error message, it looks like you access the database using user homestead on localhost database, not root on student_management. Make sure you edit the correct .env, not .env.example. cheers

要么你编辑错误的文件,要么你还没有保存。env。因为在错误消息中,看起来您使用localhost数据库上的user homestead访问数据库,而不是student_management上的root。确保您编辑了正确的.env,而不是.env.示例。干杯

#3


1  

You can use these commands to solve the problem

您可以使用这些命令来解决这个问题

php artisan cache:clear 
php artisan config:clear 
php artisan config:cache 

These commands are use to clear the cache.

这些命令用于清除缓存。

#4


0  

Add the blank quotes in front of password like this

DB_PASSWORD=""

In the case if you have an empty password.
Hope this solution will work

如果密码为空,则在密码前面添加空格引号,如DB_PASSWORD="" "。希望这个解决方案能起作用。

#5


0  

Cleaning out the system caches...for example for the PhpMyStorm IDE

清理系统缓存…例如PhpMyStorm IDE

On the main menu, choose File | Invalidate Caches/Restart. The Invalidate Caches message appears informing you that the caches will be invalidated and rebuilt on the next start. Use buttons in the dialog to invalidate caches, restart PhpStorm or both.

在主菜单中,选择File |无效缓存/重新启动。出现Invalidate缓存消息,通知您缓存将在下一次启动时失效并重新构建。在对话框中使用按钮使缓存失效,重新启动PhpStorm或同时启动PhpStorm。

#1


4  

@Tazwar Utshas

@Tazwar Utshas

You should clear the cache after changing in .env file

在.env文件中修改后,应该清除缓存

run the following commands

运行以下命令

php artisan cache:clear 
php artisan config:clear 
php artisan config:cache  

#2


1  

It's either you edit a wrong file or you have not saved the .env yet. Because in your error message, it looks like you access the database using user homestead on localhost database, not root on student_management. Make sure you edit the correct .env, not .env.example. cheers

要么你编辑错误的文件,要么你还没有保存。env。因为在错误消息中,看起来您使用localhost数据库上的user homestead访问数据库,而不是student_management上的root。确保您编辑了正确的.env,而不是.env.示例。干杯

#3


1  

You can use these commands to solve the problem

您可以使用这些命令来解决这个问题

php artisan cache:clear 
php artisan config:clear 
php artisan config:cache 

These commands are use to clear the cache.

这些命令用于清除缓存。

#4


0  

Add the blank quotes in front of password like this

DB_PASSWORD=""

In the case if you have an empty password.
Hope this solution will work

如果密码为空,则在密码前面添加空格引号,如DB_PASSWORD="" "。希望这个解决方案能起作用。

#5


0  

Cleaning out the system caches...for example for the PhpMyStorm IDE

清理系统缓存…例如PhpMyStorm IDE

On the main menu, choose File | Invalidate Caches/Restart. The Invalidate Caches message appears informing you that the caches will be invalidated and rebuilt on the next start. Use buttons in the dialog to invalidate caches, restart PhpStorm or both.

在主菜单中,选择File |无效缓存/重新启动。出现Invalidate缓存消息,通知您缓存将在下一次启动时失效并重新构建。在对话框中使用按钮使缓存失效,重新启动PhpStorm或同时启动PhpStorm。