How to close To many connection

encountering a “too many connections” error in MySQL, causing the database to disconnect, and sometimes PM2 freezing.
I have tried to solve the issue of increased max_connection size and also upgraded server space.
please suggest me any solution.

Hello @amit84
There is no single solution for this, as too many connections issue can caused by multiple reasons.
Killing/Terminating connection/s from the database side is not a long-term solution and it is something that should be fixed on the application side and mysql configuration side as well.
For example:

  1. Application/user should close the connection after work is done.
  2. Configure wait_timeout and intercative_timeout for connection on the mysql side (a temporary solution to avoid too many connection issue)

Here are some references to avoid this error,