gpt4 book ai didi

php - 如何修复 "Illuminate\Database\QueryException: SQLSTATE[HY000] [1044] Access denied for user"

转载 作者:可可西里 更新时间:2023-11-01 07:38:16 27 4
gpt4 key购买 nike

我尝试运行:php artisan migrate

也可以在 Windows 上使用 Xampp 连接到 MySQL。

我遇到了这个错误:

Illuminate\Database\QueryException  : SQLSTATE[HY000] [1044] Access
denied for user ''@'localhost' to database 'homestead' (SQL: select *
from information_schema.tables where table_schema = homestead and
table_name = migrations)

at
C:\Users\harsh\Laravel1\vendor\laravel\framework\src\Illuminate\Database\Connection.php:664
660| // If an exception occurs when attempting to run a query, we'll format the error
661| // message to include the bindings with SQL, which will make this exception a
662| // lot more helpful to the developer instead of just the database's errors.
663| catch (Exception $e) {
> 664| throw new QueryException(
665| $query, $this->prepareBindings($bindings), $e
666| );
667| }
668| Exception trace:

1 PDOException::("SQLSTATE[HY000] [1044] Access denied for user
''@'localhost' to database 'homestead'")
C:\Users\harsh\Laravel1\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70

2
PDO::__construct("mysql:host=127.0.0.1;port=3306;dbname=homestead",
"homestead", "", [])
C:\Users\harsh\Laravel1\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70

Please use the argument -v to see more details.

.env 文件:

DB_CONNECTION=mysql 
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=

最佳答案

打开.env 文件并编辑它。只需设置正确的数据库凭据:

DB_CONNECTION=mysql 
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE= // Your Database Name
DB_USERNAME= // Yout Database Username
DB_PASSWORD= // Your Database Password

如果您没有默认的用户名<,DB_USERNAME 应该设置为 root/strong> 在 xampp 中安装 MySQL。

如果数据库没有设置密码,清空DB_PASSWORD空格也要去掉(以前我同样面对这个问题,窗口将空格视为密码)

完成 .env 编辑后,请在您的终端中输入此命令以清除缓存:

php artisan config:cache

关于php - 如何修复 "Illuminate\Database\QueryException: SQLSTATE[HY000] [1044] Access denied for user",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54124262/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com