Laravel 6.4.1 SQLSTATE [HY000] [2002]连接被拒绝 [英] Laravel 6.4.1 SQLSTATE[HY000] [2002] Connection refused

查看:171
本文介绍了Laravel 6.4.1 SQLSTATE [HY000] [2002]连接被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Laravel开发的新手.我已经在Mac Mojave 10.14.6上将Xampp更新为7.3.11.在Laravel项目中,当我按下php artisan migration命令时,出现以下错误.

I am new in Laravel development. I have updated Xampp to 7.3.11 on my Mac Mojave 10.14.6. In Laravel project when I hit php artisan migrate command I got following error.

SQLSTATE [HY000] [2002]连接被拒绝(SQL:从*中选择*information_schema.tables其中table_schema = laravel和table_name= migrations and table_type ='BASE TABLE')

SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = laravel and table_name = migrations and table_type = 'BASE TABLE')

启动Xampp服务时,我的管理面板运行在 http://127.0.0.1:8080/phpmyadmin.我在Laravel中工作的项目也未与数据库连接,并说连接被拒绝.我尝试通过更改.env文件中的 DB_Port DB_Host 来尝试.我尝试清除缓存.

When I start Xampp service, my admin panel run on http://127.0.0.1:8080/phpmyadmin. My working project in Laravel is also not connecting with database saying connection refused. I tried by changing DB_Port and DB_Host in .env file. I tried by clearing cache.

任何帮助将不胜感激.

我的 .env 文件

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=

推荐答案

打开 localhost/phpmyadmin 并找到一个名为 User account 的标签.

Open localhost/phpmyadmin and find a tab called User accounts.

找到 root 用户,并在您的 .env 中设置其密码,如果创建该数据库,请不要忘记创建名为 laravel 的数据库.不存在

Find the root user and set its password in your .env and also don't forget to create the database named laravel if it doesn't exist

然后您可以清除配置缓存

Then you can clear config cache

php artisan config:clear

然后迁移

php artisan migrate

这篇关于Laravel 6.4.1 SQLSTATE [HY000] [2002]连接被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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