0

My Laravel app is working normally but every now and then I get this error SQLSTATE[HY000] [2002] Connection refused It only happens for few seconds then when I request the rest apis again it works

{message: "SQLSTATE[HY000] [2002] Connection refused", exception: "Doctrine\DBAL\Driver\PDO\Exception",…}
exception
: 
"Doctrine\\DBAL\\Driver\\PDO\\Exception"
file
: 
"/var/www/...../vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDO/Exception.php"
line
: 
18
message
: 
"SQLSTATE[HY000] [2002] Connection refused"
Wahyu Kristianto
  • 8,719
  • 6
  • 43
  • 68
Ahmed Serry
  • 33
  • 1
  • 7
  • no as my issue doesn't happen all the time, I mean the connection is working successfully but sometimes I got this error then after few seconds it works successfully again without any changes from my side – Ahmed Serry Mar 04 '23 at 14:15
  • Looks like the database is being exhausted (too many connections or similar), can you tell us what are you doing to reproduce the error? Else it is going to be imposible to help you – matiaslauriti Mar 04 '23 at 14:51
  • I just use the system for some time and then the issue happens, the server doesn't have any other load maybe except me using it to enter some data into the system – Ahmed Serry Mar 05 '23 at 18:59
  • Is the database on the same machine as the API? If that is the case, how much RAM does that machine have? If you check right now how much RAM is being used? – matiaslauriti Mar 05 '23 at 20:05
  • yes both mysql and api are running on the same machine, the machine has 2GB of RAM and currently the RAM used is 1.36 GB – Ahmed Serry Mar 06 '23 at 09:22
  • It is then possible that the machine is running out of memory. This happened to me and MySQL would throw the same error as you are sharing. Check the MySQL logs on `/var/log/` and see if you find any sudden stop or memory issues for mysql – matiaslauriti Mar 06 '23 at 09:26

0 Answers0