简体   繁体   English

SQLSTATE[HY000] [2002] 连接被拒绝 LARAVAL

[英]SQLSTATE[HY000] [2002] Connection refused LARAVEL

I am trying to run php artisan migrate on a new database I just created.我正在尝试在我刚刚创建的新数据库上运行php artisan migrate I was having many troubles with connecting to mariadb but I managed to fix it.我在连接到 mariadb 时遇到了很多麻烦,但我设法解决了它。 Now whenever i try to connect to it, for some reason I can type no password or literally any password and i still connect to it.现在,每当我尝试连接它时,出于某种原因,我无法输入密码或几乎任何密码,但我仍然可以连接到它。 I don't know if that's normal.我不知道这是否正常。 Anyway, i modified the .env file in my laravel project to无论如何,我将 Laravel 项目中的.env文件修改为

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

But i get the error SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = liberty_comerce and table_name = migrations and table_type = 'BASE TABLE') .但我收到错误SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = liberty_comerce and table_name = migrations and table_type = 'BASE TABLE') If I change DB_HOST=127.0.0.1 to DB_HOST=localhost i get the error SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from information_schema.tables where table_schema = liberty_comerce and table_name = migrations and table_type = 'BASE TABLE') .如果我将DB_HOST=127.0.0.1更改为DB_HOST=localhost我得到错误SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from information_schema.tables where table_schema = liberty_comerce and table_name = migrations and table_type = 'BASE TABLE')

I tried running我试过跑步

php artisan config:clear
php artisan config:cache
php artisan cache:clear

every time i changed anything.每次我改变任何东西。 I've been looking for answer online but nothing seems to work.我一直在网上寻找答案,但似乎没有任何效果。

Connection refused comes when .env DB_PORT doesn't match with your local db port..env DB_PORT 与您的本地数据库端口不匹配时,连接被拒绝。 so first check the port and then clear cache commands:所以首先检查端口,然后清除缓存命令:

php artisan config:clear
php artisan config:cache
php artisan cache:clear

and then do php artisan migrate .然后做php artisan migrate

我有同样的问题还没有得到解决方案,我尝试了一些事情,比如将 127.0.0.1 更改为本地主机,以及php artisan config:clear php artisan config:cache php artisan cache:clear

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM