【问题标题】:Receiving "SQLSTATE[HY000] [2002] Connection refused error" in Laravel Project在 Laravel 项目中收到“SQLSTATE [HY000] [2002] 连接被拒绝错误”
【发布时间】:2020-09-26 13:44:57
【问题描述】:

我在我的 Mac 上工作,我正在尝试连接到数据库,如 env 文件中所示,我提到了 db 名称,但在我的 laravel 项目中仍然出现此错误。我已经在核心 php 项目上尝试过它可以工作,但是在将 laravel 项目连接到数据库时出现此错误。

SQLSTATE[HY000] [2002] 连接被拒绝 (SQL: select * from information_schema.tables where table_schema = cart and table_name = migrations and table_type = 'BASE TABLE') 在 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| 

【问题讨论】:

    标签: php laravel laravel-7


    【解决方案1】:

    试试这个

    php artisan config:clear
    

    然后

    php artisan migrate
    

    如果你确定数据库已经存在

    【讨论】:

    • 我已经尝试了很多次但没有成功。在运行这个之后我得到这个....SQLSTATE[HY000] [2002] 没有这样的文件或目录(SQL:select * from information_schema.tables where table_schema = cart and table_name = migrations and table_type = 'BASE TABLE')跨度>
    • @ahmedayoub 请创建新数据库并确保名称正确,用户名和密码正确。
    猜你喜欢
    • 2017-05-04
    • 2017-09-20
    • 2020-03-26
    • 2020-12-04
    • 2020-02-27
    • 2016-11-03
    • 1970-01-01
    • 2019-08-21
    • 2019-07-18
    相关资源
    最近更新 更多