托管项目时的连接问题: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

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.