duanheye7423 2019-05-15 11:28
浏览 1849
已采纳

托管项目时的连接问题:SQLSTATE [HY000] [2002]连接被拒绝

I'm trying to connect my project laravel to an external server, it's connected just fine when it's in localhost, but when I try to host it to a server it shows me this error

SQLSTATE[HY000] [2002] Connection refused (SQL: select * from `cdr` 
where `dst` in (0, 0, 0))

This is my database.php and .env

database.php

     'mysqlExtern' => [
           'driver'    => 'mysql',
           'host'      => env('DB_HOST_EXT', '187.164.77.77'),
           'port'      => env('DB_PORT_EXT', '3306'),
           'database'  => env('DB_DATABASE_EXT', 'testDb'),
           'username'  => env('DB_USERNAME_EXT', 'xxxx'),
           'password'  => env('DB_PASSWORD_EXT', 'xxxxx'),
       ],

.env

DB_CONNECTION=mysqlExtern
DB_HOST_EXT=187.164.77.77
DB_PORT_EXT=3306
DB_DATABASE_EXT=testDb
DB_USERNAME_EXT=coga
DB_PASSWORD_EXT=RTgh457
  • 写回答

1条回答 默认 最新

  • douying1119 2019-05-15 11:47
    关注

    If it's working on localhost it means that your localhost configuration and connection code is probably correct.

    When connecting to an external server especially a database you should keep in mind that there are configurations preventing "everybody" connecting to that server (firewalls, blocked ports, IP Blacklists/Whitelists). You should contact the server administrator and figure it out. If its your server check for the mentioned above so that you can allow your application to access it.

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

报告相同问题?

悬赏问题

  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办