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

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

问题描述

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

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: select * frominformation_schema.tables 其中 table_schema = laravel 和 table_name= 迁移和 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_PortDB_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 accounts 的选项卡.

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] 连接被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Convert JSON integers and floats to strings(将JSON整数和浮点数转换为字符串)
in php how do I use preg replace to turn a url into a tinyurl(在php中,如何使用preg替换将URL转换为TinyURL)
all day appointment for ics calendar file wont work(ICS日历文件的全天约会不起作用)
trim function is giving unexpected values php(Trim函数提供了意外的值php)
Basic PDO connection to MySQL(到MySQL的基本PDO连接)
PHP number_format returns 1.00(Php number_Format返回1.00)