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

omarsow94's avatar

How to fix ' SQLSTATE[HY000] [2002] Connection refused' error.

I put the good informations but the message error still ; In local it's work but not in production

0 likes
10 replies
tisuchi's avatar

What do you mean by Good Information?

I put the good informations

You better show your connection code.

omarsow94's avatar

right values

DB_CONNECTION=mysql
DB_HOST=mydomaine.mysql.db
DB_PORT=3306
DB_DATABASE=mydatabase
DB_USERNAME=mydbname
DB_PASSWORD=secret

@tisuchi

tisuchi's avatar

@omarsow94

Yes, that's the default value. What you need to change there is-

DB_CONNECTION=mysql
DB_HOST=mydomaine.mysql.db
DB_PORT=3306
DB_DATABASE=nameOfYourDatabase
DB_USERNAME=databaseUserName
DB_PASSWORD=databasePassword

Normally DB_HOST is localhost if it is in the same hosting.

omarsow94's avatar

Yes i know , i change all values for the truth. In local , it's work but in production not @tisuchi

Ishatanjeeb's avatar

The server where you want to access database is not accessible it may be offline.Make sure your database access info all are correct.

Vijay's avatar

Try below command and let me know if you're able to connect the database.

mysql -u {username} -p{password} -h {remote server ip} {DB name}

Note: Replace your database credential

1 like
tisuchi's avatar

@omarsow94

As long as it works in the Local environment, it might be problematic in your database api permission. Make sure you have the right permission to access the DB that @Ishatanjeeb mentioned in his comment.

1 like
mdanish's avatar

Hi, I m facing same error, how to give permission from database

Please or to participate in this conversation.