Laravel 6.4.1 SQLSTATE[HY000] [2002] 连接被拒绝
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/58658735/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel 6.4.1 SQLSTATE[HY000] [2002] Connection refused
提问by Manish Mahajan
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.
我是 Laravel 开发的新手。我已在 Mac Mojave 10.14.6 上将 Xampp 更新到 7.3.11。在 Laravel 项目中,当我点击 php artisan migrate 命令时出现以下错误。
SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = laravel and table_name = migrations and table_type = 'BASE TABLE')
SQLSTATE[HY000] [2002] 连接被拒绝(SQL: select * from information_schema.tables where table_schema = laravel and table_name = migrations and table_type = 'BASE TABLE')
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.
当我启动 Xampp 服务时,我的管理面板在http://127.0.0.1:8080/phpmyadmin 上运行。我在 Laravel 中的工作项目也没有与数据库连接,说连接被拒绝。我试图通过改变DB_Port
和DB_Host
在.ENV文件。我尝试通过清除缓存。
Any Help will be appreciated.
任何帮助将不胜感激。
My .env
file
我的.env
档案
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=
回答by Salim Djerbouh
Open localhost/phpmyadmin
and find a tab called User accounts
.
打开localhost/phpmyadmin
并找到一个名为 的选项卡User accounts
。
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
找到root
用户并在您的密码中设置其密码,.env
并且不要忘记创建名为laravel
? 如果它不存在的数据库
Then you can clear config cache
然后你可以清除配置缓存
php artisan config:clear
And migrate
并迁移
php artisan migrate
Hope this helps
希望这可以帮助
回答by Tauseef Tariq
I had the same issue. It was resolved by just restarting the local host server i.e Xampp
我遇到过同样的问题。只需重新启动本地主机服务器即 Xampp 即可解决
回答by ufuk
I had the same problem and when I applied the following operations, the problem was solved.
我遇到了同样的问题,当我应用以下操作时,问题解决了。
php artisan key:generate
php artisan cache:clear
php artisan route:clear
php artisan config:clear
php artisan view:clear