MySQL ERROR 2002: [2002] Resource temporarily unavailable (trying to connect via unix:///var/lib/mysql/mysql.sock)

One day on production server I encountered this error message, So I found out a solution for it as:

There are multiple reasons, listed below:

  1. You’ve run out of memory available to MySQL.This is the most likely problem you’re facing. Each connection in MySQL’s connection pool requires memory to function, and if this resource is exhausted, no further connections can be made. Of course, the memory footprints and maximum packet sizes of various operations can be tuned in your equivalent to my.cnf if you discover this to be an issue.

You can calculate MySQL memory using this tool – http://www.mysqlcalculator.com/

This shows maximum size a MySQL should use in your environment, in my case it’s a dedicated MYSQL host so it’s easy for me to calculate Total Memory/Max_Memory_Used_by_MySQL.

2.  You’ve run out of file descriptors available to your MySQL user account.

Another common issue: if you’re trying to service requests that require file IO above the 1,024 boundary (by default), you will run into cases where the operation simply fails. This is because most systems specify a soft and hard limit on the number of open file descriptors each user can have available at one time, and walking over this threshold can cause problems.

This will usually have a series of glaringly obvious signs expressed in your log files. Check /var/log/messages and your comparable directories (for example, /var/log/mysql to see if you can find anything interesting.

In mycase I found that It’s reached Max_Memory_used_by_MYSQL due to #of concurrent connections and many sort activities and I have mentioned 4MB as sort_buffer_size.
So, I have decided to increase Max_connections and upgrade RAM, which solved the problem

Leave a comment