Laravel 5错误SQLSTATE [HY000] [1045]拒绝访问用户'homestead'@'localhost'(使用密码:YES)

时间:2021-12-03 19:19:18

I have installed Laravel 5 successfully and changed MySQL credentials in database.php file in config directory to '

我已经成功安装了Laravel 5并将config目录中的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'

我不明白为什么它说“宅基地”@“localhost”被拒绝访问

9 个解决方案

#1


24  

It's working now. I had to restart server. Thanks

它现在正在运作。我不得不重启服务器。谢谢

#2


6  

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.

和中提琴,它按预期运作良好。

#3


2  

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”

#4


2  

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

#5


1  

Please update below file.

请更新以下文件。

vendor - .env - on line#7

供应商 - .env - 第7行

 DB_HOST=localhost
 DB_DATABASE=homestead
 DB_USERNAME=homestead
 DB_PASSWORD=secret

Instead of homestead user your database, username and password. This should work for you.

而不是宅基地用户的数据库,用户名和密码。这应该适合你。

#6


0  

Pls Update .env file

请更新.env文件

 DB_HOST=localhost
 DB_DATABASE=homestead
 DB_USERNAME=homestead
 DB_PASSWORD=secret

After then restart server

然后重启服务器

#7


0  

You need to run these two commands

您需要运行这两个命令

php artisan cache:clear
php artisan config:cache

#8


0  

if you before use localhost and root your file be cached

如果你之前使用localhost和root你的文件被缓存

remove /bootstap/cache/config.php

删除/bootstap/cache/config.php

#9


0  

Instead of using this

而不是使用这个

DB_HOST=localhost
DB_DATABASE=wdcollect
DB_USERNAME=root
DB_PASSWORD=

USE this

用这个

DB_HOST=localhost
DB_DATABASE=wdcollect
DB_USERNAME=root
DB_PASSWORD=''

#1


24  

It's working now. I had to restart server. Thanks

它现在正在运作。我不得不重启服务器。谢谢

#2


6  

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.

和中提琴,它按预期运作良好。

#3


2  

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”

#4


2  

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

#5


1  

Please update below file.

请更新以下文件。

vendor - .env - on line#7

供应商 - .env - 第7行

 DB_HOST=localhost
 DB_DATABASE=homestead
 DB_USERNAME=homestead
 DB_PASSWORD=secret

Instead of homestead user your database, username and password. This should work for you.

而不是宅基地用户的数据库,用户名和密码。这应该适合你。

#6


0  

Pls Update .env file

请更新.env文件

 DB_HOST=localhost
 DB_DATABASE=homestead
 DB_USERNAME=homestead
 DB_PASSWORD=secret

After then restart server

然后重启服务器

#7


0  

You need to run these two commands

您需要运行这两个命令

php artisan cache:clear
php artisan config:cache

#8


0  

if you before use localhost and root your file be cached

如果你之前使用localhost和root你的文件被缓存

remove /bootstap/cache/config.php

删除/bootstap/cache/config.php

#9


0  

Instead of using this

而不是使用这个

DB_HOST=localhost
DB_DATABASE=wdcollect
DB_USERNAME=root
DB_PASSWORD=

USE this

用这个

DB_HOST=localhost
DB_DATABASE=wdcollect
DB_USERNAME=root
DB_PASSWORD=''