安装mysql debug环境

本文介绍如何在Linux环境下从源码编译安装MySQL Debug版本,并通过gdb进行调试的方法。包括环境准备、编译安装MySQL、初始化MySQL及使用gdb调试等步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

安装MySQL Debug环境

环境

系统环境: Linux sqlnode1 3.10.0-1062.el7.x86_64 #1 SMP Thu Jul 18 20:25:13 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
MySQL版本: 5.7.20-debug
cmake: cmake version 2.8.12.2
gcc: gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)
g++: g++ (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)
gdb: GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-120.el7

依赖

yum install gcc  gcc-c++-4.8.5-44.el7.x86_64 gdb  cmake-2.8.12.2-2.el7.x86_64 libaio-devel bison

下载

  • MySQL
    在这里插入图片描述
    wget https://downloads.mysql.com/archives/get/p/23/file/mysql-boost-5.7.20.tar.gz

编译安装MySQL

$ mkdir debug
$ cd debug
$ cmake ../ -DWITH_BOOST=/root/mysql-5.7.20/boost/boost_1_59_0 -DWITH_DEBUG=1
$ make && make install

初始化Mysql

  • 配置文件
[mysqld]
basedir=/usr/local/mysql # 源码编译安装后basedir默认在/usr/local下
datadir=/home/data/mysql/
log_error=/home/data/mysql/err.log
socket=/home/data/mysql/mysql.socket
port=3306
  • 初始化
mkdir /home/data/mysql -p 
chown mysql.mysql -R /home/data/mysql 
/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --initialize-insecure --user=mysql
  • 启动
/usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf &
  • 测试
[root@sqlnode1 mysql-5.7.20]# /usr/local/mysql/bin/mysql -uroot -p -h127.0.0.1 -P3306
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.20-debug Source distribution

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> select version();
+--------------+
| version()    |
+--------------+
| 5.7.20-debug |
+--------------+
1 row in set (0.00 sec)

mysql> 

至此mysql debug环境就已经安装好了.

gdb调试MySQL

使用gdb调试mysqldump工具为例
前提:mysql数据库的进程必须先启动

  1. 首先进入数据库的base目录:/usr/local/mysql/bin
  2. 找到mysqldump
  3. 在终端上输入
[root@localhost client]# gdb mysqldump 
GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-114.el7
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /root/source_code/mysql-5.7.20/debug/client/mysqldump...done.
(gdb)  b /root/source_code/mysql-5.7.20/client/mysqldump.c:6038
Breakpoint 1 at 0x411375: file /root/source_code/mysql-5.7.20/client/mysqldump.c, line 6038.
(gdb) p
The history is empty.
(gdb) r
Starting program: /root/source_code/mysql-5.7.20/debug/client/mysqldump 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".

Breakpoint 1, main (argc=1, argv=0x7fffffffdc18) at /root/source_code/mysql-5.7.20/client/mysqldump.c:6038
6038      MY_INIT("mysqldump");
Missing separate debuginfos, use: debuginfo-install glibc-2.17-326.el7_9.x86_64 libgcc-4.8.5-44.el7.x86_64 libstdc++-4.8.5-44.el7.x86_64
(gdb) s
my_init () at /root/source_code/mysql-5.7.20/mysys/my_init.c:91
91        if (my_init_done)
(gdb) n
94        my_init_done= TRUE;
(gdb) bt
#0  my_init () at /root/source_code/mysql-5.7.20/mysys/my_init.c:94
#1  0x000000000041138b in main (argc=1, argv=0x7fffffffdc18) at /root/source_code/mysql-5.7.20/client/mysqldump.c:6038
(gdb)   b /root/source_code/mysql-5.7.20/client/mysqldump.c:6038
Note: breakpoint 1 also set at pc 0x411375.
Breakpoint 2 at 0x411375: file /root/source_code/mysql-5.7.20/client/mysqldump.c, line 6038.
(gdb) l
89        char *str;
90
91        if (my_init_done)
92          return FALSE;
93
94        my_init_done= TRUE;
95
96      #if defined(MY_MSCRT_DEBUG)
97        set_crt_report_leaks();
98      #endif
(gdb) f
#0  my_init () at /root/source_code/mysql-5.7.20/mysys/my_init.c:94
94        my_init_done= TRUE;
(gdb)   b /root/source_code/mysql-5.7.20/client/mysqldump.c:6038
Note: breakpoints 1 and 2 also set at pc 0x411375.
Breakpoint 3 at 0x411375: file /root/source_code/mysql-5.7.20/client/mysqldump.c, line 6038.
(gdb) start
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Temporary breakpoint 4 at 0x411375: file /root/source_code/mysql-5.7.20/client/mysqldump.c, line 6038.
Starting program: /root/source_code/mysql-5.7.20/debug/client/mysqldump 
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".

Breakpoint 1, main (argc=1, argv=0x7fffffffdc18) at /root/source_code/mysql-5.7.20/client/mysqldump.c:6038
6038      MY_INIT("mysqldump");
(gdb) n
6040      compatible_mode_normal_str[0]= 0;
(gdb) n
6041      default_charset= (char *)mysql_universal_client_charset;
(gdb) n
6042      memset(&ignore_table, 0, sizeof(ignore_table));
(gdb)  b /root/source_code/mysql-5.7.20/client/mysqldump.c:6044

ok,完成

参考: https://linux265.com/course/linux-command-gdb.html

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值