【问题标题】:SQLSTATE[HY000] [2002] Connection refused LARAVEL [duplicate]SQLSTATE [HY000] [2002] 连接被拒绝 LARAVEL [重复]
【发布时间】:2021-12-17 17:02:25
【问题描述】:

我正在尝试在我刚刚创建的新数据库上运行 php artisan migrate。我在连接到 mariadb 时遇到了很多麻烦,但我设法解决了它。现在,每当我尝试连接它时,由于某种原因,我无法输入任何密码或任何密码,但我仍然可以连接到它。我不知道这是否正常。无论如何,我将 laravel 项目中的.env 文件修改为

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

但我收到错误 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')。如果我将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')

我试过跑步

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

每次我改变任何东西。我一直在网上寻找答案,但似乎没有任何效果。

【问题讨论】:

  • 我能够通过重新启动 mariadb 服务来修复这些错误,现在我得到了SQLSTATE[HY000] [1698] Access denied for user 'root'@'localhost' (SQL: select * from information_schema.tables where table_schema = liberty_comerce and table_name = migrations and table_type = 'BASE TABLE') 我尝试了在网上找到的不同解决方案,但没有一个对我有用。而且我仍然可以通过sudo mariadbsudo mariadb -u root -p 连接到mariadb,然后无论我输入什么密码,它都可以使用
  • 好的,我发现问题来自这样一个事实,即通过 root 连接到我的 mariadb 的唯一方法是使用 sudo 但 laravel 不能使用它。
  • 请创建新的数据库用户然后你可以继续它。

标签: php mysql laravel mariadb


【解决方案1】:

.env DB_PORT 与您的本地数据库端口不匹配时,连接被拒绝。所以首先检查端口和 然后清除缓存命令:

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

然后做 php artisan migrate.

【讨论】:

    【解决方案2】:

    我遇到了同样的问题还没有找到解决方案,我尝试了一些方法,例如将 127.0.0.1 更改为 localhost,并且:

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

    【讨论】:

      猜你喜欢
      • 2017-05-04
      • 2021-05-11
      • 2017-09-20
      • 2020-03-26
      • 2020-12-04
      • 2020-02-27
      • 2016-11-03
      • 1970-01-01
      • 2021-07-10
      相关资源
      最近更新 更多