M Arfan
M Arfan

Reputation: 4575

Laravel MySql Connection problem too many connections

Too many connection problem in laravel5.8 application

enter image description here

You can see there 54k+ connection in mysql and 32 is in used only how to remove unused connection so my application work fast.

enter image description here

Upvotes: 2

Views: 14168

Answers (3)

EJIRO EDWIN
EJIRO EDWIN

Reputation: 21

Connection is just a "count" of attempted connections. It does not relate to active connections nor max_used_connections.

Run the following commands simultaneously:

SHOW VARIABLES LIKE 'max_connections'

SET GLOBAL max_connections = 1000000;

Upvotes: 1

Rick James
Rick James

Reputation: 142528

Neither 54K connections since startup, nor a max of 32 connections simultaneously doing something, is "too many".

What is the real problem? Sluggishness? Find the slowest queries and let's work on speeding them up. Run SHOW FULL PROCESSLIST to see if any queries have been running for more than a few seconds; they are a prime candidate for optimizing. Or use the slowlog.

Upvotes: 1

xyz
xyz

Reputation: 578

Connection is just a "count" of attempted connections. It does not relate to active connections nor max_used_connections.

See MySQL show status - active or total connections?


If you really are having many current open connections, you should look into what these connections are. You might have a sub-optimal query in your code or a bot is spamming an open endpoint.

You can see process list by running the query

show processlist;

You can then kill connections for the short term solution or take care of whatever problem was causing the connections in the first place.

If you really do need that many connections (doubt it), you should look into scaling your database instance, e.g. by adding read replicas.

Upvotes: 0

Related Questions