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

shimana's avatar

SQLSTATE[HY000] [2002] Connection refused

Hello, I have successfully deployed my first Laravel project on a VPS. Everything seems to be working fine—I can store and display data without any issues. However, when I check the log file, I see the following error:‍‍‍‍

[previous exception] [object] (PDOException(code: 2002): SQLSTATE[HY000] [2002] Connection refused at /home/firstproject/demo/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:66)
[stacktrace]

This issue appears in the laravel.log file.

Also The following error is repeatedly appearing in the worker.log file.


In Connection.php line 825:
                                                                               
  SQLSTATE[HY000] [2002] Connection refused (Connection: mariadb, SQL: select  
   * from `cache` where `key` in (illuminate:queue:restart))                   
                                                                               

In Connector.php line 66:
                                             
  SQLSTATE[HY000] [2002] Connection refused  

my .env file:

DB_CONNECTION=mariadb
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=secret
DB_USERNAME=secret
DB_PASSWORD=secret

Does anyone know what might be causing this issue?

0 likes
4 replies
jlrdw's avatar

Try changing:

DB_CONNECTION=mariadb

to

DB_CONNECTION=mysql
1 like
shimana's avatar

@jlrdw Thank you! I made the following changes

DB_CONNECTION= mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=secret
DB_USERNAME=secret
DB_PASSWORD=secret

but I’m still getting the following errors, even though the system is working. I’m not sure what I did wrong.

[previous exception] [object] (PDOException(code: 2002): SQLSTATE[HY000] [2002] No such file or directory at /home/project/laravelproject/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:66)

and

[2025-02-28 11:22:15] production.ERROR: SQLSTATE[HY000] [2002] No such file or directory (Connection: mysql, SQL: select * from `cache` where `key` in (illuminate:queue:restart)) {"exception":"[object] (Illuminate\\Database\\QueryException(code: 2002): SQLSTATE[HY000] [2002] No such file or directory (Connection: mysql, SQL: select * from `cache` where `key` in (illuminate:queue:restart)) at /home/project/laravelproject/vendor/laravel/framework/src/Illuminate/Database/Connection.php:825)
[stacktrace]
Snapey's avatar

errors in worker.log means your queue setup is not quite right. Do you run your worker(s) under a different user account? Do your queued jobs actually work? Are you intending to use database for queued jobs?

1 like
shimana's avatar
shimana
OP
Best Answer
Level 1

The issue has been resolved. I added this line into ENV file, and no more errors are being logged.

DB_SOCKET=/var/lib/mysql/mysql.sock‍‍

Please or to participate in this conversation.