mysqld Keeps Forking Until the Process Table Fills Up

Problem

I installed database/mysql5-server from the pkgsrc-2007Q1 branch. When I started it, it just kept forking until the process table filled up. The mysql log messages looked like this:

073028 14:30:57  Starting mysqld daemon with databases from /store/mysql
073028 14:30:57  mysqld started
073028 14:30:57  Starting mysqld daemon with databases from /store/mysql
073028 14:30:57  mysqld started
073028 14:30:57  Starting mysqld daemon with databases from /store/mysql
073028 14:30:57  mysqld started

...

/usr/pkg/bin/mysqld: Cannot fork
/usr/pkg/bin/mysqld: Cannot fork
/usr/pkg/bin/mysqld: Cannot fork
/usr/pkg/bin/mysqld: Cannot fork
/usr/pkg/bin/mysqld: Cannot fork
/usr/pkg/bin/mysqld: Cannot fork
usage: chown [-R [-H | -L | -P]] [-fhv] [owner][:group] file ...
073228 14:32:30  STOPPING server from pid file /var/mysql/charon.pid
073228 14:32:30  mysqld ended
073228 14:32:30  STOPPING server from pid file /var/mysql/charon.pid
073228 14:32:30  mysqld ended
073228 14:32:30  STOPPING server from pid file /var/mysql/charon.pid
073228 14:32:30  mysqld ended
073228 14:32:30  STOPPING server from pid file /var/mysql/charon.pid

...

In /var/log/messages I got:
May 28 14:35:49 charon /netbsd: proc: table is full - increase kern.maxproc or NPROC

Fix

Obivously something goes wrong when mysqld tries to fork. I finally found the reason to be that it was trying to fork a mysqld process from /usr/pkg/bin/mysqld, which is a shell script, instead of /usr/pkg/libexec/mysqld, which is the actual mysqld.

Passing --ledir=/usr/pkg/libexec to mysqld, or mysqld_safe resp., fixes this issue. You can pass it in the mysqld_flags variable in /etc/rc.conf.