I have a FreeBSD 8 system running ZFS, with a MySQL 5.5 server which is about 355GB and projected to grow to be a couple of Terabytes.

MySQL is triggering errors about "Too many open files" on /etc/hosts.allow. We don't expressly use /etc/hosts.allow, but it is used by hosts_access(3) (libwrap.a), which is used by many things.

mysqld[1234]: warning: /etc/hosts.allow, line 15: cannot open /etc/hosts.allow: Too many open files

But when I check 't seem to be hitting any actual limits. The number of open files reported by kern.openfiles stays below 40,000 over a sustained period, and our limit is substantially higher:

# sysctl -a |grep files
kern.maxfiles: 204800
kern.maxfilesperproc: 184320
kern.openfiles: 38191

# ulimit -n

Openfiles should be set to unlimited:

# grep openfiles /etc/login.conf

MySQL says it should be able to open 184320 file handles:

# mysqladmin variables | grep open_files_limit
| open_files_limit                              |     184320                |

And some information from the perspective of the MySQL user. I stopped mysql and hacked /usr/local/etc/rc.d/mysql-server to print out these variables, so this should represent the MySQL environment. Note that the number 184320 is consistent with the above.

# /usr/local/etc/rc.d/mysql-server.stefantest start
Starting mysql.
cpu time               (seconds, -t)  unlimited
file size           (512-blocks, -f)  unlimited
data seg size           (kbytes, -d)  33554432
stack size              (kbytes, -s)  524288
core file size      (512-blocks, -c)  unlimited
max memory size         (kbytes, -m)  unlimited
locked memory           (kbytes, -l)  unlimited
max user processes              (-u)  5547
open files                      (-n)  184320
virtual mem size        (kbytes, -v)  unlimited
swap limit              (kbytes, -w)  unlimited
sbsize                   (bytes, -b)  unlimited
pseudo-terminals                (-p)  unlimited

And, for easy reference here are the descriptions for the sysctls:

kern.maxfiles: Maximum number of files
kern.openfiles: System-wide number of open files
kern.maxfilesperproc: Maximum files allowed open per process


  • 4
    ulimit isn't global, are you sure that's the same ulimit your MySQL is running with?
    – derobert
    Mar 4, 2013 at 20:06
  • 1
    So, can I see what the ulimit value is for the MySQL daemon, and can I change the ulimit value for the daemon without stopping the daemon? I know I can set ulimit in the startup script or the shell environment, but that would require that I interrupt the database. Mar 4, 2013 at 20:31
  • 1
    Look in /proc, under the subdir with the PID of your mysql service. You can cat limits to see what mysql is running with. You can also change them on the fly (with newer kernels): echo -n "Max open files=soft_value:hard_value" > /proc/$PID/limits (as root of course)
    – lornix
    Aug 17, 2013 at 13:38
  • 1
    @lornix: this is FreeBSD. I've never used BSD myself, but I'm not sure if FreeBSD actually supports /proc/*/limits. Sep 16, 2013 at 22:37
  • 1
    /proc isn't mounted by default on FreeBSD, but do it yourself with sudo mount -t procfs proc /proc, see procfs(5) for more info. Once you have /proc mounted, look at /proc/$PID/rlimit file
    – zygis
    Sep 17, 2013 at 18:13

2 Answers 2


Check /etc/login.conf and figure out which login class your mysql user assigned to. It's probably default or daemon. If you want to alter the limits for your user, create a new class, assign your user to that class, change the limts for that class as you like and then run "cap_mkdb /etc/login.conf"

If you haven't read this yet, do: http://www.freebsd.org/doc/handbook/users-limiting.htm

Processes started at system startup by /etc/rc are assigned to the daemon login class.


On some OS the limits are set to avoid security problem to regular user, you should consider reading whant in the man limits.conf
This file defines the limits per process like max number of thread or max number of open file. The limitation use face could come from there. /etc/security/limits.conf

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .