【问题标题】:Connection refused SQL: select * from information_schema.tables where table_schema = firstdb and table_name = migrations and table_type = 'BASE TABLE连接被拒绝 SQL: select * from information_schema.tables where table_schema = firstdb and table_name = migrations and table_type = 'BASE TABLE
【发布时间】:2020-07-29 05:34:53
【问题描述】:

我安装并打开了 XAMPP,这是我访问 phpmyadmin 页面的方式。我在 phpmyadmin 中创建了一个名为“firstdb”的数据库。

我还在本地存储的 laravel 文件中创建了身份验证。我正在尝试使用 php artisan migrate 迁移表,但出现以下错误。

user@Andress-MacBook-Pro admin-panel % php artisan migrate

   Illuminate\Database\QueryException 

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

  at vendor/laravel/framework/src/Illuminate/Database/Connection.php:671
    667|         // If an exception occurs when attempting to run a query, we'll format the error
    668|         // message to include the bindings with SQL, which will make this exception a
    669|         // lot more helpful to the developer instead of just the database's errors.
    670|         catch (Exception $e) {
  > 671|             throw new QueryException(
    672|                 $query, $this->prepareBindings($bindings), $e
    673|             );
    674|         }
    675| 

      +37 vendor frames 
  38  artisan:37
      Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

我到处找,请帮忙。

【问题讨论】:

  • 这里的错误是“连接被拒绝”。它试图运行的查询是附带的,所以你的标题不会帮助你得到答案。据推测,这只是您的 Laravel 设置中的配置问题。
  • 补充 Greg 所说的内容,检查数据库主机、用户名、密码等是否根据您的 XAMPP 环境要求正确设置。

标签: php laravel database-migration migrate


【解决方案1】:

这可能是您的.env 文件中的错误mysql 端口号。检查您的.env 文件并确保端口号与mysql 使用的相同。

【讨论】:

  • 是的,要补充 Nelson 所说的内容,请始终确保在 .env 文件中添加正确的值,并在 .env 文件中添加此类连接和环境特定变量。
  • 由于您使用的是XAMPP,答案可能会有所不同。对我来说,我使用的是 Homestead,我的解决方案很简单。根据 Laravel 的文档,将 .env DB_Username 更改为 homestead,将 DB_Password 更改为 secret。然后我可以进行迁移。因此,只需在您的 .env 文件中设置您用于连接到 XAMPP 数据库的相同凭据。
  • 好答案@MichaelBerrios。
  • @NelsonKatale 很高兴它有帮助。
【解决方案2】:

我注意到命令行输出中的密码与 env 文件中的实际密码有些奇怪。原来我的密码中有一个数字符号,它被切断了。

因此,在运行php artisan migrate 后检查输出,并确保密码与您的环境中的密码实际匹配(以及与此相关的所有信息)。解决方法是在不匹配时添加引号。

DB_PASSWORD=abcdefghijklmonp5#Q

会变成

DB_PASSWORD='abcdefghijklmonp5#Q'

【讨论】:

    【解决方案3】:

    除了确保您的所有配置都是正确的转义密码(带引号)之外,我在 linux 上进行全新安装时遇到了类似的问题。

    SQLSTATE[HY000] [1045] 用户“用户名”@“本地主机”的访问被拒绝(使用密码:YES)(SQL:从 information_schema.tables 中选择 *,其中 table_schema = studentaffairs 和 table_name = 迁移和 table_type = 'BASE TABLE ')

    为了解决这个问题,我确保运行 composer update 并且为了更好的措施,我运行了 npm run dev

    然后它能够​​毫无问题地迁移。

    【讨论】:

      【解决方案4】:

      .env 文件中的 DB_CONNECTION=127.0.0.7 更改为 mysql

      【讨论】:

        猜你喜欢
        • 2021-04-21
        • 2018-11-05
        • 1970-01-01
        • 2016-01-31
        • 2020-07-26
        • 2022-10-25
        • 1970-01-01
        • 2021-05-24
        • 2023-01-30
        相关资源
        最近更新 更多