Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

rmlakhani's avatar

SQLSTATE[HY000] [2002] Connection refused SELECT Query - Remote DB

Hello all,

I am new to Laravel and I have been learning this pretty well however I am stuck at a particular position, that position is to query the phpMyAdmin db. What I am attempting to do is to build the application locally on my machine while tapping into the database that is hosted.

I have done this through basic php but I'm getting a connection refused when loading the page.

Below is my .env and database.php files. I have removed the passwords in both for security reasons.

.env

APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:JJFkVL455YB+jkXul+x2C9hE7h+hSc/ww/ELNENDk88=
APP_DEBUG=true
APP_URL=http://localhost

LOG_CHANNEL=stack

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=taqiuddi_ball_hockey
DB_USERNAME=taqiuddin
DB_PASSWORD=*******

database.php

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

        'mysql' => [
            'driver' => 'mysql',
            'host' => env('DB_HOST', 'localhost'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'taqiuddi_ball_hockey'),
            'username' => env('DB_USERNAME', 'taqiuddin'),
            'password' => env('DB_PASSWORD', *******),
            'unix_socket' => env('DB_SOCKET', ''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'strict' => true,
            'engine' => null,
        ],
0 likes
12 replies
Cronix's avatar

build the application locally on my machine while tapping into the database that is hosted.

You probably need to specify the ip address that the db is hosting on.

DB_HOST=localhost
rmlakhani's avatar

@Cronix So I am logged into the phpMyAdmin Panel and the only thing that I see related to the server is localhost:3306 at the top of the page. Is that what you're referring to?

Sorry if I am asking a very noob-ish question.

I should also mention that when I used the other connection I had built I had the following for the server:

$host = '127.0.0.1';
jlrdw's avatar

You'd probably be better off just duplicating the DB on local for development purposes.

C I Know

It does not answer the OP's question of how to connect to the hosted database.

But My advise is to not to it that way, if OP wants to anyway, OP can just skip my reply altogether.

rmlakhani's avatar

@Cronix not it isn't, any ideas where the server information maybe located in phpMyAdmin Panel?

Cronix's avatar

how are you accessing the phpmyadmin panel? Where is that hosted?

jlrdw's avatar

@rmlakhani export that db from phpmyadmin to local, and import to local dev mysql.

Get sqlyog community or something similar.

Cronix's avatar

@rmlakhani Does cpanel tell you? I don't know what to tell you. Your cpanel/hosting company should be able to tell you.

Snapey's avatar

127.0.0.1 is the same as localhost. This is NOT the same as the IP address you need if you are trying to access the database from another location.

The only solution is to get the database server IP address from your hosting company, however, they may not even permit remote access (its a security risk).

jlrdw's avatar

I love this forum.

@RMLAKHANI do what you wish, but I had the hope you would try and setup a proper development environment. No response needed, as your environment is your business.

Please or to participate in this conversation.