连接被拒绝的 SQL: select * from information_schema.tables where table_schema = firstdb and table_name = migrations and table_type = 'BASE TABLE

And*_*rio 6 php migrate database-migration laravel

我安装并打开了 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))
Run Code Online (Sandbox Code Playgroud)

我到处找,请帮忙。

Nel*_*ale 5

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

  • 是的,要添加 Nelson 所说的内容,请始终确保在 .env 文件中添加正确的值,并在 .env 文件中添加此类连接和环境特定变量。 (2认同)
  • 由于您使用的是 XAMPP,所以答案可能会有所不同。对我来说,我正在使用 Homestead,我的解决方案很简单。根据 Laravel 文档,将 .env DB_Username 更改为 homestead,将 DB_Password 更改为 Secret。然后我就可以进行迁移了。因此,只需在 .env 文件中设置用于连接 XAMPP 数据库的相同凭据即可。 (2认同)

Ric*_*ard 5

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

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

DB_PASSWORD=abcdefghijklmonp5#Q

会成为

DB_PASSWORD='abcdefghijklmonp5#Q'