While some may think I’m daft, I have a legitimate reason for wanting to crash mysqld. However first we need to find a way to crash it.
Great thanks to Alan K, Mark L, Harrison and Hartmut on #mysql-dev for several suggestions and a config option I was unaware of. My investigation even lead to a documentation bug logged as #51739.
My first thought was to find a known bug and if necessary install the correct version to test that. A good one was suggested, Bug #48508 which fails on several versions that I will use to demonstrate with, however the simplest way is to issue kill -11
By default, no core file will be produced which is what I’m seeking but with the right options this is possible. First, the user running mysqld probably has a core file limit size of 0.
$ ulimit -c 0
You can fix this with with ulimit or you can specify this in the [mysqld_safe] section with core-file-size=unlimited
$ ulimit -c unlimited $ ulimit -c unlimited
The option I was not aware of is you also have to also specify core-file in your my.cnf
I also for my CentOS 5.4 installation ran the following kernel commands, but this may be unnecessary.
sudo /sbin/sysctl -w kernel.core_pattern="core" sudo /sbin/sysctl -w fs.suid_dumpable= 1
It is now easy to produce a core file.
$ bin/mysqld_safe & $ killall -11 mysqld $ bin/mysqld_safe: line 137: 2656 Segmentation fault (core dumped) ... 100304 16:46:43 mysqld_safe Number of processes running now: 0 100304 16:46:43 mysqld_safe mysqld restarted $ find . -name "core*" ./data/core.99999
NOTE: Do no run killall on a multi-instance server. I use this syntax here only for simplicity in presentation. It is best to run ps and kill the appropriate pid.
On a side note, I also tried to produce a core on Mac OS X without success. I’d still like to document that way, so if anybody can assist please ping me.
Nick Westerlund says
on OS X, it is quite easy.
1) make sure core-file is enabled in my.cnf
2) check ulimit
3) kill mysql
4) check for the file in /cores
taxbiex:bin nick$ cat my
taxbiex:bin nick$ ulimit
taxbiex:bin nick$ ulimit -c
taxbiex:bin nick$ ./mysqld_safe –defaults-file=my &
taxbiex:bin nick$ ps x | grep mysqld
31444 s005 S 0:00.02 /bin/sh ./mysqld_safe –defaults-file=my
31491 s005 S 0:00.06 /usr/local/mysql/bin/mysqld –defaults-file=my –basedir=/usr/local/mysql –datadir=/usr/local/mysql/data –user=mysql –log-error=/usr/local/mysql/data/taxbiex.local.err –pid-file=/usr/local/mysql/data/taxbiex.local.pid
31493 s005 R+ 0:00.00 grep mysqld
taxbiex:bin nick$ kill -11 31491
taxbiex:bin nick$ ls /cores
And there you have it, a core on OS X 10.6.2
Awesome this! How about marking a table as crashed intentionally? I want to intentionally mark a table as crashed. How do I do this? Thanks.