douyo770657 2018-06-03 20:15
浏览 97
已采纳

SQLSTATE [HY000] [2002]尝试将连接laravel数据库添加到Heroku时拒绝连接

So I have a site on Heroku, which loads fine as long I don't go to a page that requires a database connection. What happens when I do land on one of those pages, is I get this error:

PDOException in Connector.php line 55: SQLSTATE[HY000] [2002] Connection refused

I'm using db4free.net to try to access a MySQL database. This is my database.php file. The ****** masking the actual values.

'default' => env('DB_CONNECTION', 'mysql-production'),

'mysql-production' => [
            'driver' => 'mysql',
            'host' => env('DB_HOST', 'db4free.net'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'en*******'),
            'username' => env('DB_USERNAME', '*******'),
            'password' => env('DB_PASSWORD', '*******'),
            'unix_socket' => env('DB_SOCKET', ''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'strict' => true,
            'engine' => null,
        ],

This my env file:

APP_ENV=local
APP_DEBUG=true
APP_KEY=base64:tUWa6AteuAOfEAh/IKx3c13tJEzSmS4La8QdKlEgByQ=
APP_URL=http://localhost

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=enviro-2
DB_USERNAME=root
DB_PASSWORD=

CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

The env file is ignored by git.

Prior to trying db4free.net I tried following the steps in this article https://mattstauffer.com/blog/laravel-on-heroku-using-a-postgresql-database/ but I still have the exact same problem. I also set the APP_KEY in the Heroku config variables to match the one in my env file.

Anyone have any ideas on why I get this error?

  • 写回答

1条回答 默认 最新

  • doulubashang6936 2018-06-03 21:13
    关注

    your connection details in .env file in incorrect. you should write your credentials details in .env file as well as database.php file

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

    报告相同问题?

    悬赏问题

    • ¥80 用PE可以更改原win11系统的环境变量吗?
    • ¥20 win10商店接入问题
    • ¥15 java 这种树形框吗
    • ¥40 找同学帮敲Python代码
    • ¥15 MYSQL 订单的商品明细重复计算问题
    • ¥15 微信实时共享位置修改
    • ¥100 TG的session协议号转成直登号号后客户端登录几分钟后自动退出设备
    • ¥50 共模反馈回路的小信号增益
    • ¥15 arduino ssd1306函数与tone函数放歌代码不兼容问题
    • ¥70 0.96版本hbase的row_key里含有双引号,无法deleteall