MySQL8.0源码学习(8.0.18编译安装+debug基础调试)

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
云数据库 RDS PostgreSQL,集群系列 2核4GB
简介: MySQL 8.0 debug 源码

一、编译安装MySQL8.0.18

1.1 安装依赖包

yum -y install ntpdate gcc gcc-c++ ncurses ncurses-devel cmake readline-devel zlib.x86_64 zlib-devel.x86_64 bison libcurl-* net-tool* tree nmap sysstat lrzsz dos2unix telnet.x86_64 nethogs iftop iotop unzip ftp.x86_64 xfs* expect vim wget psmisc openssh-client* libaio libaio1 libnuma openssl-devel bzip2 flex clang

1.2 基础环境配置

#关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
#关闭postfix
systemctl stop postfix
systemctl disable postfix
#关闭SELINUX
sed -i 's/^SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config
setenforce 0
getenforce
#关闭numa
sed -i 's/GRUB_CMDLINE_LINUX.*/GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=centos\/root rd.lvm.lv=centos\/swap rhgb quiet numa=off"/g' /etc/default/grub
grub2-mkconfig -o /etc/grub2.cfg
cat /etc/grub2.cfg
reboot
cat /proc/cmdline
dmesg | grep -i numa
#内核参数修改
echo "vm.swappiness=10">>/etc/sysctl.conf
echo "net.ipv4.tcp_tw_recycle=1">>/etc/sysctl.conf
echo "net.ipv4.tcp_tw_reuse=1">>/etc/sysctl.conf
echo "vm.dirty_background_ratio=8">>/etc/sysctl.conf
echo "* soft nproc 65536" >>/etc/security/limits.conf
echo "* hard nproc 65536" >>/etc/security/limits.conf
echo "* soft nofile 65536" >>/etc/security/limits.conf
echo "* hard nproc 65536" >>/etc/security/limits.conf
#创建用户
useradd -M -s /sbin/nologin mysql
#创建相关目录
mkdir -pv /data/{conf,redo1,redo2,mysql3306/{data,tmp,logs}}
#授权
chown -R mysql:mysql /data/mysql3306/

1.3 配置环境变量

export PATH=$PATH:/usr/local/mysql/bin:
echo 'export PATH=$PATH:/usr/local/mysql/bin' >> /etc/profile

1.4 升级gcc

mkdir /usr/local/gcc && cd /usr/local/gcc
wget https://github.com/gcc-mirror/gcc/archive/gcc-5_5_0-release.tar.gz
tar xf gcc-5.5.0.tar.xz
cd gcc-gcc-5_5_0-release
./contrib/download_prerequisites
mkdir build && cd build
../configure --enable-checking=release --enable-languages=c,c++ --disable-multilib
make && make install

1.5 升级cmake

mkdir /usr/local/cmake && cd /usr/local/cmake
wget https://github.com/Kitware/CMake/releases/download/v3.14.5/cmake-3.14.5.tar.Z
./bootstrap
make && make install
#如果出现以下类似错误,需要更新libstdc++:
libstdc++.so.6: version `CXXABI_1.3.9' not found (required by ./destructor)
strings ./libstdc++.so.6 | grep CXXABI
CXXABI_1.3
CXXABI_1.3.1
CXXABI_1.3.2
CXXABI_1.3.3
CXXABI_1.3.4
CXXABI_1.3.5
CXXABI_1.3.6
CXXABI_1.3.7
CXXABI_TM_1
mv /usr/lib64/libstdc++.so.6.0.19 /tmp/
cp /usr/local/gcc/gcc-gcc-5_5_0-release/build/x86_64-unknown-linux-gnu/libstdc++-v3/src/.libs/libstdc++.so.6.0.21 /usr/lib64/
mv /usr/lib64/libstdc++.so.6 /tmp/
ln -s libstdc++.so.6.0.21 libstdc++.so.6

1.6 编译安装MySQL

cd ~
tar xf  mysql-boost-8.0.18.tar.gz
cd mysql-8.0.18
cmake . \
-DWITH_BOOST=/root/mysql-8.0.18/boost/boost_1_70_0 \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/data/mysql3306/data \
-DWITHOUT_CSV_STORAGE_ENGINE=1 \
-DWITHOUT_FEDERATED_STORAGE_ENGINE=1 \
-DWITHOUT_ARCHIVE_STORAGE_ENGINE=1 \
-DFORCE_INSOURCE_BUILD=1 \
-DWITH_SSL=system \
-DWITH_DEBUG=1 \
-DCMAKE_CXX_COMPILER=/usr/local/bin/g++ \
-DCMAKE_C_COMPILER=/usr/local/bin/gcc
# -j 表示使用几个CPU同时编译
make -j 2
make install

1.7 初始化&启动数据库

#编辑配置文件
vi /data/conf/my.cnf
#建立软链接
ln -s /data/conf/my.cnf /etc/my.cnf
#初始化数据库
mysqld --defaults-file=/etc/my.cnf --initialize-insecure &
#启动数据库
mysqld_safe --defaults-file=/etc/my.cnf &
#登陆后修改密码
mysql
alter user root@localhost identified by 'xxx';

二、调试环境配置

2.1 调试工具基本使用

#安装调试工具gdb
yum install -y gdb

  gdb常用选项:

命令 命令缩写 命令说明
attach 挂接进程的PID
detach 取消挂接的进程
list l 显示多行源代码
break b 设置断点,程序运行到断点的位置会停下来
info i 描述程序的状态
run r 开始运行程序
display disp 跟踪查看某个变量,每次停下来都显示它的值
step s 执行下一条语句,如果该语句为函数调用,则进入函数执行其中的第一条语句
next n 执行下一条语句,如果该语句为函数调用,不会进入函数内部执行(即不会一步步地调试函数内部语句)
print p 打印内部变量值
continue c 继续程序的运行,直到遇到下一个断点
set var name=v 设置变量的值
start st 开始执行程序,在main函数的第一条语句前面停下来
file 装入需要调试的程序
kill k 终止正在调试的程序
watch 监视变量值的变化
backtrace bt 查看函数调用信息(堆栈)
frame f 查看栈帧
quit q 退出GDB环境

2.2 MySQL和OS线程的对应关系

  mysqld是一个单进程多线程的程序,进程实际上就是运行中的程序,一个进程中可以包含一个或多个线程。一个进程内部的所有线程都拥有相同的代码程序、堆、全局变量、共享库等,但是每个线程拥有自己独立栈空间和寄存器,他们共享进程的虚拟内存地址空间。在Linux中线程也叫轻量级进程(LWP)。进程是内存分配的最小单位,线程是CPU调度的最小单位,也就是说如果CPU是多核,那么多个线程可以达到并行处理的效果,内核直接调度线程。在OS上通过ps -eLlf可以查看线程ID LWP:
_
  通过performance_schema.threads表可以查看操作系统线程号与mysql哪个功能线程相对应:

root@mysql8 16:42:  [(none)]> select THREAD_ID,PROCESSLIST_ID,THREAD_OS_ID,name,TYPE from performance_schema.threads;
+-----------+----------------+--------------+---------------------------------------------+------------+
| THREAD_ID | PROCESSLIST_ID | THREAD_OS_ID | name                                        | TYPE       |
+-----------+----------------+--------------+---------------------------------------------+------------+
|         1 |           NULL |         3117 | thread/sql/main                             | BACKGROUND |
|         3 |           NULL |         3124 | thread/innodb/io_ibuf_thread                | BACKGROUND |
|         4 |           NULL |         3125 | thread/innodb/io_log_thread                 | BACKGROUND |
|         5 |           NULL |         3126 | thread/innodb/io_read_thread                | BACKGROUND |
|         6 |           NULL |         3127 | thread/innodb/io_read_thread                | BACKGROUND |
|         7 |           NULL |         3128 | thread/innodb/io_read_thread                | BACKGROUND |
|         8 |           NULL |         3129 | thread/innodb/io_read_thread                | BACKGROUND |
|         9 |           NULL |         3130 | thread/innodb/io_read_thread                | BACKGROUND |
|        10 |           NULL |         3131 | thread/innodb/io_read_thread                | BACKGROUND |
|        11 |           NULL |         3132 | thread/innodb/io_read_thread                | BACKGROUND |
|        12 |           NULL |         3133 | thread/innodb/io_read_thread                | BACKGROUND |
|        13 |           NULL |         3134 | thread/innodb/io_write_thread               | BACKGROUND |
|        14 |           NULL |         3135 | thread/innodb/io_write_thread               | BACKGROUND |
|        15 |           NULL |         3136 | thread/innodb/io_write_thread               | BACKGROUND |
|        16 |           NULL |         3137 | thread/innodb/io_write_thread               | BACKGROUND |
|        17 |           NULL |         3138 | thread/innodb/io_write_thread               | BACKGROUND |
|        18 |           NULL |         3139 | thread/innodb/io_write_thread               | BACKGROUND |
|        19 |           NULL |         3140 | thread/innodb/io_write_thread               | BACKGROUND |
|        20 |           NULL |         3141 | thread/innodb/io_write_thread               | BACKGROUND |
|        21 |           NULL |         3142 | thread/innodb/page_flush_coordinator_thread | BACKGROUND |
|        22 |           NULL |         3143 | thread/innodb/page_flush_thread             | BACKGROUND |
|        23 |           NULL |         3144 | thread/innodb/page_flush_thread             | BACKGROUND |
|        24 |           NULL |         3145 | thread/innodb/page_flush_thread             | BACKGROUND |
|        25 |           NULL |         3146 | thread/innodb/log_checkpointer_thread       | BACKGROUND |
|        26 |           NULL |         3147 | thread/innodb/log_closer_thread             | BACKGROUND |
|        27 |           NULL |         3148 | thread/innodb/log_flush_notifier_thread     | BACKGROUND |
|        28 |           NULL |         3149 | thread/innodb/log_flusher_thread            | BACKGROUND |
|        29 |           NULL |         3150 | thread/innodb/log_write_notifier_thread     | BACKGROUND |
|        30 |           NULL |         3151 | thread/innodb/log_writer_thread             | BACKGROUND |
|        31 |           NULL |         3152 | thread/innodb/srv_lock_timeout_thread       | BACKGROUND |
|        32 |           NULL |         3153 | thread/innodb/srv_error_monitor_thread      | BACKGROUND |
|        33 |           NULL |         3154 | thread/innodb/srv_monitor_thread            | BACKGROUND |
|        34 |           NULL |         3156 | thread/innodb/buf_resize_thread             | BACKGROUND |
|        35 |           NULL |         3157 | thread/innodb/srv_master_thread             | BACKGROUND |
|        36 |           NULL |         3158 | thread/innodb/dict_stats_thread             | BACKGROUND |
|        37 |           NULL |         3159 | thread/innodb/fts_optimize_thread           | BACKGROUND |
|        38 |           NULL |         3160 | thread/mysqlx/worker                        | BACKGROUND |
|        39 |           NULL |         3161 | thread/mysqlx/worker                        | BACKGROUND |
|        40 |           NULL |         3162 | thread/mysqlx/acceptor_network              | BACKGROUND |
|        41 |           NULL |         3163 | thread/mysqlx/acceptor_network              | BACKGROUND |
|        44 |           NULL |         3166 | thread/innodb/buf_dump_thread               | BACKGROUND |
|        45 |           NULL |         3167 | thread/innodb/clone_gtid_thread             | BACKGROUND |
|        46 |           NULL |         3168 | thread/innodb/srv_purge_thread              | BACKGROUND |
|        47 |           NULL |         3168 | thread/innodb/srv_purge_thread              | BACKGROUND |
|        48 |           NULL |         3169 | thread/innodb/srv_worker_thread             | BACKGROUND |
|        49 |           NULL |         3169 | thread/innodb/srv_worker_thread             | BACKGROUND |
|        50 |           NULL |         3170 | thread/innodb/srv_worker_thread             | BACKGROUND |
|        51 |           NULL |         3170 | thread/innodb/srv_worker_thread             | BACKGROUND |
|        52 |           NULL |         3171 | thread/innodb/srv_worker_thread             | BACKGROUND |
|        53 |           NULL |         3171 | thread/innodb/srv_worker_thread             | BACKGROUND |
|        54 |              4 |         3172 | thread/sql/event_scheduler                  | FOREGROUND |
|        55 |           NULL |         3173 | thread/sql/signal_handler                   | BACKGROUND |
|        56 |              6 |         3174 | thread/sql/compress_gtid_table              | FOREGROUND |
|        59 |              9 |         3177 | thread/sql/one_connection                   | FOREGROUND |
+-----------+----------------+--------------+---------------------------------------------+------------+
54 rows in set (0.01 sec)

2.4 mysql调试基本使用

  启动gdb:

gdb
GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-115.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/>.
(gdb)

  我们使用attach命令挂接mysql

gdb
GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-115.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/>.
(gdb) attach 3117
Attaching to process 3117
Reading symbols from /usr/local/mysql/bin/mysqld...done.
Reading symbols from /lib64/libpthread.so.0...(no debugging symbols found)...done.
[New LWP 14341]
...
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
Loaded symbols for /lib64/libpthread.so.0
Reading symbols from /usr/local/mysql/bin/../lib/private/libprotobuf-lite.so.3.6.1...done.
Loaded symbols for /usr/local/mysql/bin/../lib/private/libprotobuf-lite.so.3.6.1
Reading symbols from /lib64/libcrypt.so.1...(no debugging symbols found)...done.
Loaded symbols for /lib64/libcrypt.so.1
Reading symbols from /lib64/librt.so.1...(no debugging symbols found)...done.
Loaded symbols for /lib64/librt.so.1
Reading symbols from /lib64/libssl.so.10...Reading symbols from /lib64/libssl.so.10...(no debugging symbols found)...done.
(no debugging symbols found)...done.
Loaded symbols for /lib64/libssl.so.10
Reading symbols from /lib64/libcrypto.so.10...Reading symbols from /lib64/libcrypto.so.10...(no debugging symbols found)...done.
(no debugging symbols found)...done.
Loaded symbols for /lib64/libcrypto.so.10
Reading symbols from /lib64/libdl.so.2...(no debugging symbols found)...done.
Loaded symbols for /lib64/libdl.so.2
Reading symbols from /lib64/libnuma.so.1...(no debugging symbols found)...done.
Loaded symbols for /lib64/libnuma.so.1
Reading symbols from /lib64/libstdc++.so.6...done.
Loaded symbols for /lib64/libstdc++.so.6
Reading symbols from /lib64/libm.so.6...(no debugging symbols found)...done.
Loaded symbols for /lib64/libm.so.6
Reading symbols from /lib64/libgcc_s.so.1...(no debugging symbols found)...done.
Loaded symbols for /lib64/libgcc_s.so.1
Reading symbols from /lib64/libc.so.6...(no debugging symbols found)...done.
Loaded symbols for /lib64/libc.so.6
Reading symbols from /lib64/ld-linux-x86-64.so.2...(no debugging symbols found)...done.
Loaded symbols for /lib64/ld-linux-x86-64.so.2
Reading symbols from /lib64/libfreebl3.so...Reading symbols from /usr/lib/debug/usr/lib64/libfreebl3.so.debug...done.
done.
Loaded symbols for /lib64/libfreebl3.so
Reading symbols from /lib64/libgssapi_krb5.so.2...Reading symbols from /lib64/libgssapi_krb5.so.2...(no debugging symbols found)...done.
(no debugging symbols found)...done.
Loaded symbols for /lib64/libgssapi_krb5.so.2
Reading symbols from /lib64/libkrb5.so.3...Reading symbols from /lib64/libkrb5.so.3...(no debugging symbols found)...done.
(no debugging symbols found)...done.
Loaded symbols for /lib64/libkrb5.so.3
Reading symbols from /lib64/libcom_err.so.2...Reading symbols from /lib64/libcom_err.so.2...(no debugging symbols found)...done.
(no debugging symbols found)...done.
Loaded symbols for /lib64/libcom_err.so.2
Reading symbols from /lib64/libk5crypto.so.3...Reading symbols from /lib64/libk5crypto.so.3...(no debugging symbols found)...done.
(no debugging symbols found)...done.
Loaded symbols for /lib64/libk5crypto.so.3
Reading symbols from /lib64/libz.so.1...Reading symbols from /lib64/libz.so.1...(no debugging symbols found)...done.
(no debugging symbols found)...done.
Loaded symbols for /lib64/libz.so.1
Reading symbols from /lib64/libkrb5support.so.0...Reading symbols from /lib64/libkrb5support.so.0...(no debugging symbols found)...done.
(no debugging symbols found)...done.
Loaded symbols for /lib64/libkrb5support.so.0
Reading symbols from /lib64/libkeyutils.so.1...Reading symbols from /lib64/libkeyutils.so.1...(no debugging symbols found)...done.
(no debugging symbols found)...done.
Loaded symbols for /lib64/libkeyutils.so.1
Reading symbols from /lib64/libresolv.so.2...(no debugging symbols found)...done.
Loaded symbols for /lib64/libresolv.so.2
Reading symbols from /lib64/libselinux.so.1...Reading symbols from /lib64/libselinux.so.1...(no debugging symbols found)...done.
(no debugging symbols found)...done.
Loaded symbols for /lib64/libselinux.so.1
Reading symbols from /lib64/libpcre.so.1...Reading symbols from /lib64/libpcre.so.1...(no debugging symbols found)...done.
(no debugging symbols found)...done.
Loaded symbols for /lib64/libpcre.so.1
Reading symbols from /lib64/libnss_files.so.2...(no debugging symbols found)...done.
Loaded symbols for /lib64/libnss_files.so.2
0x00007fe69f0d2bed in poll () from /lib64/libc.so.6
Missing separate debuginfos, use: debuginfo-install glibc-2.17-292.el7.x86_64 keyutils-libs-1.5.8-3.el7.x86_64 krb5-libs-1.15.1-37.el7_7.2.x86_64 libcom_err-1.42.9-16.el7.x86_64 libgcc-4.8.5-39.el7.x86_64 libnuma1-2.0.12-4.1.x86_64 libselinux-2.5-14.1.el7.x86_64 openssl-libs-1.0.2k-19.el7.x86_64 pcre-8.32-17.el7.x86_64 zlib-1.2.7-18.el7.x86_64

  从输出中可以看出缺少一些包,需要额外安装:

#安装对应版本的debuginfo
rpm -ivh kernel-debuginfo-common-x86_64-3.10.0-1062.el7.x86_64.rpm
rpm -ivh kernel-debuginfo-3.10.0-1062.el7.x86_64.rpm
#安装相关包
yum install -y nss-softokn-debuginfo --nogpgcheck
yum install -y yum-utils
debuginfo-install glibc-2.17-292.el7.x86_64 keyutils-libs-1.5.8-3.el7.x86_64 krb5-libs-1.15.1-37.el7_7.2.x86_64 libcom_err-1.42.9-16.el7.x86_64 libgcc-4.8.5-39.el7.x86_64 libnuma1-2.0.12-4.1.x86_64 libselinux-2.5-14.1.el7.x86_64 openssl-libs-1.0.2k-19.el7.x86_64 pcre-8.32-17.el7.x86_64 zlib-1.2.7-18.el7.x86_64

  下面来完整的演示调试过程

#首先获取mysqld进程的PID
[root@mysql8 tmp]# ps -ef | grep mysql
root       8371   8230  0 17:41 pts/0    00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf
mysql      9916   8371  1 17:41 pts/0    00:00:12 /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/data/mysql3306/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql3306/logs/error.log --open-files-limit=65535 --pid-file=mysql8.pid --socket=/data/mysql3306/data/mysql.sock --port=3306
#然后使用gdb命令进行调试
[root@mysql8 ~]# gdb /usr/local/mysql/bin/mysqld 9916
GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-115.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 /usr/local/mysql/bin/mysqld...done.
Attaching to program: /usr/local/mysql/bin/mysqld, process 9916
Reading symbols from /lib64/libpthread.so.0...Reading symbols from /usr/lib/debug/usr/lib64/libpthread-2.17.so.debug...done.
done.
[New LWP 10064]
...
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
Loaded symbols for /lib64/libpthread.so.0
Reading symbols from /usr/local/mysql/bin/../lib/private/libprotobuf-lite.so.3.6.1...done.
Loaded symbols for /usr/local/mysql/bin/../lib/private/libprotobuf-lite.so.3.6.1
Reading symbols from /lib64/libcrypt.so.1...Reading symbols from /usr/lib/debug/usr/lib64/libcrypt-2.17.so.debug...done.
done.
Loaded symbols for /lib64/libcrypt.so.1
Reading symbols from /lib64/librt.so.1...Reading symbols from /usr/lib/debug/usr/lib64/librt-2.17.so.debug...done.
done.
Loaded symbols for /lib64/librt.so.1
Reading symbols from /lib64/libssl.so.10...Reading symbols from /usr/lib/debug/usr/lib64/libssl.so.1.0.2k.debug...done.
done.
Loaded symbols for /lib64/libssl.so.10
Reading symbols from /lib64/libcrypto.so.10...Reading symbols from /usr/lib/debug/usr/lib64/libcrypto.so.1.0.2k.debug...done.
done.
Loaded symbols for /lib64/libcrypto.so.10
Reading symbols from /lib64/libdl.so.2...Reading symbols from /usr/lib/debug/usr/lib64/libdl-2.17.so.debug...done.
done.
Loaded symbols for /lib64/libdl.so.2
Reading symbols from /lib64/libnuma.so.1...done.
Loaded symbols for /lib64/libnuma.so.1
Reading symbols from /lib64/libstdc++.so.6...done.
Loaded symbols for /lib64/libstdc++.so.6
Reading symbols from /lib64/libm.so.6...Reading symbols from /usr/lib/debug/usr/lib64/libm-2.17.so.debug...done.
done.
Loaded symbols for /lib64/libm.so.6
Reading symbols from /lib64/libgcc_s.so.1...Reading symbols from /usr/lib/debug/usr/lib64/libgcc_s-4.8.5-20150702.so.1.debug...done.
done.
Loaded symbols for /lib64/libgcc_s.so.1
Reading symbols from /lib64/libc.so.6...Reading symbols from /usr/lib/debug/usr/lib64/libc-2.17.so.debug...done.
done.
Loaded symbols for /lib64/libc.so.6
Reading symbols from /lib64/ld-linux-x86-64.so.2...Reading symbols from /usr/lib/debug/usr/lib64/ld-2.17.so.debug...done.
done.
Loaded symbols for /lib64/ld-linux-x86-64.so.2
Reading symbols from /lib64/libfreebl3.so...Reading symbols from /usr/lib/debug/usr/lib64/libfreebl3.so.debug...done.
done.
Loaded symbols for /lib64/libfreebl3.so
Reading symbols from /lib64/libgssapi_krb5.so.2...Reading symbols from /usr/lib/debug/usr/lib64/libgssapi_krb5.so.2.2.debug...done.
done.
Loaded symbols for /lib64/libgssapi_krb5.so.2
Reading symbols from /lib64/libkrb5.so.3...Reading symbols from /usr/lib/debug/usr/lib64/libkrb5.so.3.3.debug...done.
done.
Loaded symbols for /lib64/libkrb5.so.3
Reading symbols from /lib64/libcom_err.so.2...Reading symbols from /usr/lib/debug/usr/lib64/libcom_err.so.2.1.debug...done.
done.
Loaded symbols for /lib64/libcom_err.so.2
Reading symbols from /lib64/libk5crypto.so.3...Reading symbols from /usr/lib/debug/usr/lib64/libk5crypto.so.3.1.debug...done.
done.
Loaded symbols for /lib64/libk5crypto.so.3
Reading symbols from /lib64/libz.so.1...Reading symbols from /usr/lib/debug/usr/lib64/libz.so.1.2.7.debug...done.
done.
Loaded symbols for /lib64/libz.so.1
Reading symbols from /lib64/libkrb5support.so.0...Reading symbols from /usr/lib/debug/usr/lib64/libkrb5support.so.0.1.debug...done.
done.
Loaded symbols for /lib64/libkrb5support.so.0
Reading symbols from /lib64/libkeyutils.so.1...Reading symbols from /usr/lib/debug/usr/lib64/libkeyutils.so.1.5.debug...done.
done.
Loaded symbols for /lib64/libkeyutils.so.1
Reading symbols from /lib64/libresolv.so.2...Reading symbols from /usr/lib/debug/usr/lib64/libresolv-2.17.so.debug...done.
done.
Loaded symbols for /lib64/libresolv.so.2
Reading symbols from /lib64/libselinux.so.1...Reading symbols from /usr/lib/debug/usr/lib64/libselinux.so.1.debug...done.
done.
Loaded symbols for /lib64/libselinux.so.1
Reading symbols from /lib64/libpcre.so.1...Reading symbols from /usr/lib/debug/usr/lib64/libpcre.so.1.2.0.debug...done.
done.
Loaded symbols for /lib64/libpcre.so.1
Reading symbols from /lib64/libnss_files.so.2...Reading symbols from /usr/lib/debug/usr/lib64/libnss_files-2.17.so.debug...done.
done.
Loaded symbols for /lib64/libnss_files.so.2
0x00007f88d3ab4bed in poll () at ../sysdeps/unix/syscall-template.S:81
81      T_PSEUDO (SYSCALL_SYMBOL, SYSCALL_NAME, SYSCALL_NARGS)
#设置断点,比如在mysql_execute_command函数设置断点
(gdb) b mysql_execute_command
Breakpoint 1 at 0x350d370: file /usr/local/tools/mysql-8.0.18/sql/sql_parse.cc, line 2625.
#再起一个终端连接到MySQL,执行命令
select version();
#此时在gdb会话终端,会停在断点处,执行命令:p thd->m_query_string,可以看到断点处,thd变量内部的成员变量记录着当前正在执行的SQL语句:
(gdb) p thd->m_query_string
$1 = {str = 0x7f87b000c6f8 "select version()", length = 16}
#此时执行bt命令查看函数调用信息:
(gdb) bt
#0  mysql_execute_command (thd=0x7f87b0000d70, first_level=true)
    at /usr/local/tools/mysql-8.0.18/sql/sql_parse.cc:2625
#1  0x000000000351561a in mysql_parse (thd=0x7f87b0000d70, parser_state=0x7f87d40f0b20)
    at /usr/local/tools/mysql-8.0.18/sql/sql_parse.cc:5257
#2  0x000000000350aa63 in dispatch_command (thd=0x7f87b0000d70, com_data=0x7f87d40f1bd0,
    command=COM_QUERY) at /usr/local/tools/mysql-8.0.18/sql/sql_parse.cc:1765
#3  0x0000000003508fa8 in do_command (thd=0x7f87b0000d70)
    at /usr/local/tools/mysql-8.0.18/sql/sql_parse.cc:1273
#4  0x00000000036ca595 in handle_connection (arg=0x87c16b0)
    at /usr/local/tools/mysql-8.0.18/sql/conn_handler/connection_handler_per_thread.cc:302
#5  0x0000000005183038 in pfs_spawn_thread (arg=0x89c8800)
    at /usr/local/tools/mysql-8.0.18/storage/perfschema/pfs.cc:2854
#6  0x00007f88d5600e65 in start_thread (arg=0x7f87d40f2700) at pthread_create.c:307
#7  0x00007f88d3abf88d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:111
#使用c命令继续运行,直到遇到下一个断点

三、总结

  本文简单介绍了如何编译安装MySQL8.0,并且进行简单的调试。

相关实践学习
如何在云端创建MySQL数据库
开始实验后,系统会自动创建一台自建MySQL的 源数据库 ECS 实例和一台 目标数据库 RDS。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
12月前
|
存储 Oracle 关系型数据库
mysql存储过程调试方法
mysql存储过程调试方法
736 0
|
19天前
|
安全 关系型数据库 MySQL
Linux下安装mysql8.0(以tar.xz包安装--编译安装)
通过上述步骤,您完成了从下载、编译、安装到配置MySQL 8.0的全过程。此过程虽然较为复杂,但提供了对MySQL安装环境的完全控制,有助于满足特定的部署需求。在实际操作中,根据具体的系统环境,可能还需调整部分步骤或解决未预见的依赖问题。始终参考官方文档和社区资源,保持安装过程与最新版本的兼容性。
349 67
|
15天前
|
关系型数据库 MySQL Linux
在 CentOS 7 中通过编译源码方式安装 MySQL 数据库的详细步骤
本文介绍了在 CentOS 7 中通过编译源码方式安装 MySQL 数据库的详细步骤,包括准备工作、下载源码、编译安装、配置服务等,并与使用 RPM 包安装进行了对比,帮助读者根据需求选择合适的方法。编译源码安装虽然复杂,但提供了更高的定制性和灵活性。
131 2
|
17天前
|
关系型数据库 MySQL Linux
在 CentOS 7 中通过编译源码方式安装 MySQL 数据库的详细步骤
【10月更文挑战第7天】本文介绍了在 CentOS 7 中通过编译源码方式安装 MySQL 数据库的详细步骤,包括准备工作、下载源码、编译安装、配置 MySQL 服务、登录设置等。同时,文章还对比了编译源码安装与使用 RPM 包安装的优缺点,帮助读者根据自身需求选择合适的方法。
32 3
|
5月前
|
存储 安全 Java
基于Java+MySQL停车场车位管理系统详细设计和实现(源码+LW+调试文档+讲解等)
基于Java+MySQL停车场车位管理系统详细设计和实现(源码+LW+调试文档+讲解等)
|
Ubuntu 安全 关系型数据库
百度搜索:蓝易云【Ubuntu 18.04系统编译安装MySQL 5.7教程。】
现在,您已经成功地在Ubuntu 18.04上编译和安装了MySQL 5.7。请注意,这只是基本的安装过程,您可能需要进一步配置和保护您的MySQL实例。确保在实际操作中根据您的需求进行适当的配置和调整,并设置安全的密码策略。
140 0
|
3月前
|
关系型数据库 MySQL Linux
【一键解锁神秘力量!】CentOS 7 通过编译源码方式安装 MySQL 数据库 —— 从零到英雄的数据库安装实战秘籍!
【8月更文挑战第9天】随着业务增长,对数据库的需求日益提高。在 CentOS 7 中,通过编译源码安装 MySQL 可提供更高定制性和灵活性。本文详细介绍从准备环境、下载源码、配置编译参数到安装 MySQL 的全过程,并对比 RPM 包安装方法,帮助读者根据需求选择合适方案。实践时需注意备份数据、选择合适版本、确保安全性和调优性能等要点。
191 1
|
5月前
|
关系型数据库 MySQL 数据库
实时计算 Flink版操作报错合集之下载了mysql的cdc的demo,在本地调试时,报错:找不到这个包,该怎么办
在使用实时计算Flink版过程中,可能会遇到各种错误,了解这些错误的原因及解决方法对于高效排错至关重要。针对具体问题,查看Flink的日志是关键,它们通常会提供更详细的错误信息和堆栈跟踪,有助于定位问题。此外,Flink社区文档和官方论坛也是寻求帮助的好去处。以下是一些常见的操作报错及其可能的原因与解决策略。
167 0
|
6月前
|
关系型数据库 MySQL Linux
MySQL免编译安装和用户管理(转)
MySQL免编译安装和用户管理(转)
27 1
|
5月前
|
关系型数据库 MySQL Linux
centos linux mysql 5.5脚本全自动源码包 编译安装
centos linux mysql 5.5脚本全自动源码包 编译安装
56 0