Monday, September 1, 2014

mysql – Error in accept: Too many open files

One server is running both mysql and apache together,but the mysql get down every four hours.From PHP,it’s said ‘Error establshing a database connection’.From mysql error log,i got the some records like below:
’121029  2:47:38 [ERROR] Error in accept: Too many open files’
i know that mysql server has a config directive of open_files_limit which limit the number of file descripteors mysqld can use.so i need to check what the value in use for the current running mysqld server,from mysql client console,

You can also check the config with following command:


# netstat -atnp|grep 3306
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      5596/mysqld
 
# cat /proc/5596/limits
Limit                     Soft Limit           Hard Limit           Units
Max cpu time              unlimited            unlimited            seconds
Max file size             unlimited            unlimited            bytes
Max data size             unlimited            unlimited            bytes
Max stack size            10485760             unlimited            bytes
Max core file size        0                    unlimited            bytes
Max resident set          unlimited            unlimited            bytes
Max processes             200704               200704               processes
Max open files            1185                 1185                 files
Max locked memory         32768                32768                bytes
Max address space         unlimited            unlimited            bytes
Max file locks            unlimited            unlimited            locks
Max pending signals       200704               200704               signals
Max msgqueue size         819200               819200               bytes
Max nice priority         0                    0


so now we need to adjust mysql server configuration to make it feel comfortalbe.You decide the open_files_limit value by considering following factor:the databases amount, the max_connections and the table_cache value. You can also increase the number to a little higher you think is appropriate,then tune it by mysql server running status.


# vim /etc/my.cnf
[mysqld]
open_files_limit = 3000
 
save to quit and then restart msyql server
#/etc/init.d/mysqld restart