dbms가 내부에서 어떻게 동작하는지 확인하기 위해 종종 gdb 로 디버깅을 하는 경우가 있습니다.

gdb 로 디버깅 할 때 소스코드의 어떤 부분이 호출되고 , 어떤 상태인지 확인하려면 db 를 rpm 설치나 tar 파일 압축풀어서 설치하는 게 아니라

소스코드를 컴파일하며 설치해야 합니다. 이번 글에서는 mysql 8.0.17 을 소스코드로 설치하는 방법을 공유하겠습니다.

 

0. 설치환경

MYSQL 8.0.17
O/S : CentOS 7.7 / 64bit

 

1. pre requirements

boost : 1.69  
cmake : 3.15.1 이상
gcc : 5.4 이상

 

-. boost 

[root@06ada8a879ba engn001]# wget https://dl.bintray.com/boostorg/release/1.69.0/source/boost_1_69_0.tar.gz
[root@06ada8a879ba engn001]# tar xvfz boost_1_70_0.tar.gz 

-. cmake

[root@06ada8a879ba engn001]# wget https://github.com/Kitware/CMake/releases/download/v3.15.1/cmake-3.15.1.tar.gz
[root@06ada8a879ba engn001]# tar xvfz cmake-3.15.1.tar.gz
[root@06ada8a879ba engn001]# cd cmake-3.15.1
[root@06ada8a879ba cmake-3.15.1]#./bootstrap 
[root@06ada8a879ba cmake-3.15.1]# make
[root@06ada8a879ba cmake-3.15.1]# make install
[root@06ada8a879ba cmake-3.15.1]# cmake --version
cmake version 3.15.1

-.gcc

 
[root@06ada8a879ba engn001]# yum -y install centos-release-scl
[root@06ada8a879ba engn001]# yum -y install devtoolset-6-gcc*
[root@06ada8a879ba engn001]# scl enable devtoolset-6 bash
[root@06ada8a879ba engn001]# gcc --version
gcc (GCC) 6.3.1 20170216 (Red Hat 6.3.1-3)
Copyright (C) 2016 Free Software Foundation, Inc.
 

2. mysql compile

 
[root@06ada8a879ba engn001]# wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.17.tar.gz
[root@06ada8a879ba engn001]# tar xvfz mysql-8.0.17.tar.gz
[root@06ada8a879ba engn001]# cd muysql-8.0.17.tar.gz
 
 
cmake \
-DCMAKE_INSTALL_PREFIX=/engn001/mysql \
-DMYSQL_UNIX_ADDR=/engn001/mysql/data/mysql.sock \
-DDEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_bin \
-DWITH_EXTRA_CHARSETS=all \
-DMYSQL_DATADIR=/engn001/mysql/data \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=/engn001/boost_1_69_0 \
-DMYSQL_TCP_PORT=3306 \
-DENABLE_DOWNLOADS=1 \
-DFORCE_INSOURCE_BUILD=1 \
-DWITH_SSL=system \
-DWITH_DEBUG=1
option의 의미는 아래 내용 참고
* source configuration option - https://dev.mysql.com/doc/mysql-sourcebuild-excerpt/5.5/en/source-configuration-options.html
 
[root@localhost mysql]#  /engn001/mysql/bin/mysqld --defaults-file=/engn001/mysql/my.cnf --initialize-insecure --basedir=/engn001/mysql
[root@localhost mysql]# /engn001/mysql/bin/mysqld --defaults-file=/engn001/mysql/my.cnf --debug='d:t:i:F:L:o,/engn001/mysql/logs/debug.err' &
 
 
 
gdb -p mysqld

Loaded symbols for /lib64/libnss_files.so.2
0x00007f0f14935bed 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 libselinux-2.5-14.1.el7.x86_64 libstdc++-4.8.5-39.el7.x86_64 nss-softokn-freebl-3.44.0-5.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
(gdb) b main
Breakpoint 1 at 0x2b9dfc5: file /engn001/mysql-8.0.17/sql/main.cc, line 25.
(gdb) bt
#0  0x00007f0f14935bed in poll () from /lib64/libc.so.6
#1  0x0000000002eec46b in Mysqld_socket_listener::listen_for_connection_event (this=0x92e1510) at /engn001/mysql-8.0.17/sql/conn_handler/socket_connection.cc:1328
#2  0x0000000002bbdcaa in Connection_acceptor<Mysqld_socket_listener>::connection_event_loop (this=0x9261cd0) at /engn001/mysql-8.0.17/sql/conn_handler/connection_acceptor.h:64
#3  0x0000000002bb0d3c in mysqld_main (argc=66, argv=0x902a218) at /engn001/mysql-8.0.17/sql/mysqld.cc:6978
#4  0x0000000002b9dfd6 in main (argc=3, argv=0x7ffd461657c8) at /engn001/mysql-8.0.17/sql/main.cc:25