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

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

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?