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

booni3's avatar

SQL Connection refused, randomly on Forge.

I am using forge, hosted on Digital Ocean.x

Every few days I get this error when trying to login or view any login side pages:

SQLSTATE[HY000] [2002] Connection refused (SQL: select * from `users` where `email` = [email protected] limit 1)

Pages that do not require auth or database queries are unaffected and the issue can be fixed by restarting SQL.

However, this happens every few days and I am lost where to start debugging. No other errors are logged in Sentry and there are very few database queries happening. Last time this happened it was over the weekend when there would have been no queries happening at all. I wondered it it could be timing out due to inactivity but obviously this should not be happening.

I have a few light crons running all of the time, but they do not hit the DB at any point.

0 likes
7 replies
munazzil's avatar

@lambooni

Use as like below in your UserController validate .

    'email' => 'sometimes|required|email|unique:users,email,'.request()->user->id,
D9705996's avatar

The error you are getting is from MySQL and not directly related to your code. You need to review if you MySQL daemon is accessible from the command line using

mysql -u <%USERNAME%> -p <%DATABASE%>

You will also need to review your mysql logs to identify why you are randomly unable to connect to your atabasee.

booni3's avatar

Just before MYSQL disconnects I get the error message:

Received disconnect from 222.239.10.150 port 58260:11: Bye Bye [preauth]

This is an attack of some kind I assume. My server is setup with DO and Forge. I assumed Forge would set the firewall as standard, but it seems not. Ill give that a go and see if it makes a difference!

booni3's avatar

Ok... Turns out I did not really know where to look! SQL logs stored in /var/logs pointed towards running out of memory. I did not expect this as I have very little running other than a single queue worker with 2 hourly jobs on Redis/Horizon. Turns out Redis uses a LOT of memory!

I have upgraded the server and hope this will help.

1 like
D9705996's avatar

You can configure the maximum amount of memory that redis will use

maxmemory 512mb

The redis FAQ has good details on memory usage

https://redis.io/topics/faq

If you have resolved yiur issue can you please mark the discussion as solved.

1 like
booni3's avatar

Thanks @D9705996 . Do you know if there is any detrimental performance hit on decreasing Redis memory? Will it have capability of running less jobs, or would it be main in relation to cache?

Please or to participate in this conversation.