在 Laravel 中选择 MySQL 作为默认数据库后出现“Illuminate\Database\QueryException”错误

问题描述 投票:0回答:1

我最近尝试使用 VS Code 终端将我的 Laravel 应用程序配置为使用 MySQL 作为默认数据库。在设置过程中,选择MySQL后,遇到如下提示:

默认数据库已更新。您想运行默认迁移吗?(是/否):

选择“是,”后,我遇到错误:

Illuminate\Database\QueryException

  SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it (Connection: mysql, SQL: select table_name as `name`, (data_length + index_length) as `size`, table_comment as `comment`, engine as `engine`, table_collation as `collation` from information_schema.tables where table_schema = 'mydemoapp' and table_type in ('BASE TABLE', 'SYSTEM VERSIONED') order by table_name)

  at vendor\laravel\framework\src\Illuminate\Database\Connection.php:813
    809▕                     $this->getName(), $query, $this->prepareBindings($bindings), $e
    810▕                 );
    811▕             }
    812▕
  ➜ 813▕             throw new QueryException(
    814▕                 $this->getName(), $query, $this->prepareBindings($bindings), $e
    815▕             );
    816▕         }
    817▕     }

  1   vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:65
      PDOException::("SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it")

  2   vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:65
      PDO::__construct("mysql:host=127.0.0.1;port=3306;dbname=mydemoapp", "root", Object(SensitiveParameterValue), [])


  New to Laravel? Check out our bootcamp and documentation. Build something amazing!

Screenshot of the error

我尝试了什么:

我尝试将 Laravel 应用程序配置为使用 MySQL 作为默认数据库。在设置过程中,我选择 MySQL 作为默认数据库选项,并同意在出现提示时运行默认迁移。

除此之外我没有尝试过其他任何东西,因为我刚刚开始学习 laravel

我的期待:

我希望迁移能够顺利进行,不会出现任何错误。但是,在选择“yes”运行默认迁移后,我遇到了“Illuminate\Database\QueryException”错误。

我正在寻求帮助以了解为什么会发生此错误以及如何解决它。任何见解或建议将不胜感激。谢谢!

mysql laravel
1个回答
0
投票

首先检查你的mysql服务器是否正在运行? 第二次检查您是否在 .env 文件中配置了 mysql 凭据?

© www.soinside.com 2019 - 2024. All rights reserved.