MySQL使用core-file 还原堆栈信息

1、打开linux的core文件配置:ulimit -c unlimited
2、配置 core-file dump:
echo 2 >/proc/sys/fs/suid_dumpable
echo 1 >/proc/sys/kernel/core_uses_pid
3、指定core文件存放目录:mkdir /data/core && chmod 777 /data/core && echo "/data/core/core" > /proc/sys/kernel/core_pattern
4、在[mysqld]下面添加“core-file”并重启实例

1、开启一个事物

mysql> set session autocommit = 0;
Query OK, 0 rows affected (0.00 sec)

mysql> begin;
Query OK, 0 rows affected (0.00 sec)

mysql> insert zs(name) values('hello');
Query OK, 1 row affected (0.00 sec)

2、杀掉MySQLD,注意事物并没commit

[root@zhangshuo core]# kill -11 8781
[root@zhangshuo core]# ll
total 185496
-rw------- 1 root mysql 945090560 Oct 29 12:13 core.8781
[1]+  Segmentation fault      (core dumped) /data/didi/base_5.7/bin/mysqld --defaults-file=/data/didi/mysql/my.cnf.13308 --user=mysql

3、启动gdb调试core-file

[root@zhangshuo core]# gdb -c ./core.8781 --args /data/didi/base_5.7/bin/mysqld --defaults-file=/data/didi/mysql/my.cnf.13308

Loaded symbols for /data/didi/base_5.7/lib/plugin/semisync_slave.so
Core was generated by `/data/didi/base_5.7/bin/mysqld --defaults-file=/data/didi/mysql/my.cnf.13308 --'.
Program terminated with signal 11, Segmentation fault.
#0  0x00007f011f6c897c in pthread_kill () from /lib64/libpthread.so.0
Missing separate debuginfos, use: debuginfo-install glibc-2.12-1.209.el6_9.2.x86_64 libaio-0.3.107-10.el6.x86_64 libgcc-4.4.7-18.el6_9.2.x86_64 libstdc++-4.4.7-18.el6_9.2.x86_64 nss-softokn-freebl-3.14.3-23.3.el6_8.x86_64 numactl-2.0.9-2.el6.x86_64

4、还原当时堆栈

(gdb) where
#0  0x00007f011f6c897c in pthread_kill () from /lib64/libpthread.so.0
#1  0x00000000007d1b44 in handle_fatal_signal (sig=11) at /export/home/pb2/build/sb_0-30854123-1538633287.09/mysql-5.7.24/sql/signal_handler.cc:220
#2  
#3  0x00007f011e218383 in poll () from /lib64/libc.so.6
#4  0x0000000000df0879 in Mysqld_socket_listener::listen_for_connection_event (this=0x3fd0d60) at /export/home/pb2/build/sb_0-30854123-1538633287.09/mysql-5.7.24/sql/conn_handler/socket_connection.cc:852
#5  0x00000000007cc1ed in connection_event_loop (argc=106, argv=0x3e6f188) at /export/home/pb2/build/sb_0-30854123-1538633287.09/mysql-5.7.24/sql/conn_handler/connection_acceptor.h:66
#6  mysqld_main (argc=106, argv=0x3e6f188) at /export/home/pb2/build/sb_0-30854123-1538633287.09/mysql-5.7.24/sql/mysqld.cc:5139
#7  0x00007f011e157d1d in __libc_start_main () from /lib64/libc.so.6
#8  0x00000000007c1d69 in _start ()
(gdb) info frame
Stack level 0, frame at 0x7fffe9db9440:
 rip = 0x7f011f6c897c in pthread_kill; saved rip 0x7d1b44
 called by frame at 0x7fffe9db94c0
 Arglist at 0x7fffe9db9430, args: 
 Locals at 0x7fffe9db9430, Previous frame's sp is 0x7fffe9db9440
 Saved registers:
  rip at 0x7fffe9db9438
(gdb) 

你可能感兴趣的:(MySQL使用core-file 还原堆栈信息)