如何修复"Illuminate \ Database \ QueryException:SQLSTATE [HY000] [1044]用户拒绝访问" [英] How to fix "Illuminate\Database\QueryException: SQLSTATE[HY000] [1044] Access denied for user"

查看:3186
本文介绍了如何修复"Illuminate \ Database \ QueryException:SQLSTATE [HY000] [1044]用户拒绝访问"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试运行:php artisan migrate

还可以在Windows上使用Xampp连接到MySQL.

Also to connect to MySQL using Xampp on Windows.

我遇到了这个错误:

Illuminate \ Database \ QueryException:SQLSTATE [HY000] [1044]访问 用户'@'localhost'被拒绝到数据库'homestead'(SQL:select * 来自information_schema.tables,其中table_schema =宅基地和 table_name =迁移)

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)

在 C:\ Users \ harsh \ Laravel1 \ vendor \ laravel \ framework \ src \ Illuminate \ Database \ Connection.php:664 660 |//如果在尝试运行查询时发生异常,我们将格式化错误 661 |//消息以包含与SQL的绑定,这将使此异常成为 662 |//对开发人员有更多帮助,而不仅仅是数据库的错误. 663 | catch(例外$ e){

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 |抛出新的QueryException( 665 | $ query,$ this-> prepareBindings($ bindings),$ e 666 | ); 667 | } 668 |异常跟踪:

664| throw new QueryException( 665| $query, $this->prepareBindings($bindings), $e 666| ); 667| } 668| Exception trace:

1 PDOException::("SQLSTATE [HY000] [1044]用户的访问被拒绝 "@'localhost'到数据库'homestead'")) C:\ Users \ harsh \ Laravel1 \ vendor \ laravel \ framework \ src \ Illuminate \ Database \ Connectors \ Connector.php:70

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", 宅基地",",[]) 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

请使用参数-v查看更多详细信息.

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 文件并进行编辑.只需设置正确的数据库凭证:

Open the .env file and edit it. Just set up correct DB credentials:

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 

如果在 xampp .

如果未在数据库上设置密码,请清除它 DB_PASSWORD ,还必须删除空白空间(过去我也遇到过这个问题,窗口将空格作为密码)

If no password is set on the database, clear it DB_PASSWORD, empty space must also be removed(In the past I've also faceout this problem, window consider blank space as a password)

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

After completion of .env edit please enter this command in your terminal for clear cache:

php artisan config:cache

这篇关于如何修复"Illuminate \ Database \ QueryException:SQLSTATE [HY000] [1044]用户拒绝访问"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆