There may be times you need to set custom per-process limits or attributes. It is possible to patch mysqld_safe, but using a wrapper script is easier to implement. In earlier versions, you could use mysqld_safe’s mysqld= option to specify the path to your wrapper script, but this feature was removed as of 5.5.52, 5.6.33 and 5.7.15.
Currently the simplest solution is to rename the existing mysqld (e.g. to mysqld.bin), and put your script named mysqld in the same directory.
Here are some example wrapper scripts:
1. To increase the number of threads allowed, use “ulimit -u“:
#!/bin/sh DIR=$(dirname "$0") ulimit -u 10000 exec "$DIR/mysqld.bin" "$@"
2. To set the core-file size limit, use “ulimit -c“:
#!/bin/sh DIR=$(dirname "$0") ulimit -c unlimited exec "$DIR/mysqld.bin" "$@"
3. To prevent the OOM-killer from aborting mysqld, set oom_score_adj:
#!/bin/sh DIR=$(dirname "$0") echo "-1000" > /proc/self/oom_score_adj exec "$DIR/mysqld.bin" "$@"
4. To enable the NUMA interleaved memory allocation, use numactl:
#!/bin/sh DIR=$(dirname "$0") exec /usr/bin/numactl --interleave all "$DIR/mysqld.bin" "$@"
5. To set the CPU affinity, use taskset:
#!/bin/sh DIR=$(dirname "$0") exec /bin/taskset -c 0-7,8-11 "$DIR/mysqld.bin" "$@"
6. To record PAM authentication debugging information in the error log:
#!/bin/sh DIR=$(dirname "$0") export AUTHENTICATION_PAM_LOG=1 exec "$DIR/mysqld.bin" "$@"
7. To load an alternative malloc library such as tcmalloc:
#!/bin/sh DIR=$(DIRNAME "$0") LIB=/path/to/your/tcmalloc.so export LD_LIBRARY_PATH=$(dirname "$LIB"):$LD_LIBRARY_PATH export LD_PRELOAD="$LIB" exec "$DIR/mysqld.bin" "$@"