clion mysql調(diào)試環(huán)境搭建
下載代碼
git clone https://github.com/mysql/mysql-server.git
使用clion搭建調(diào)試環(huán)境
因?yàn)閏lion自帶cmake項(xiàng)目侦啸,所以搭建不需要額外操作,只需要open 項(xiàng)目就好
#mysqld 參數(shù):
--defaults-file=/data1/mycode/mysql_debug/mysql-8.0.18/mysql_stuff/etc/my3311.cnf --user=mysql --basedir=/data1/mycode/mysql_debug/mysql-8.0.18/mysql_stuff/install --datadir=/data1/mycode/mysql_debug/mysql-8.0.18/mysql_stuff/data
初始化mysql實(shí)例
/data1/mycode/mysql_debug/mysql_stuff/install/bin/mysqld --initialize --basedir=/data1/mycode/mysql_debug/mysql_stuff/install --datadir=/data1/mycode/mysql_debug/mysql_stuff/data --user=mysql
./scripts/mysql_install_db.sh --srcdir=. --ldata=/data1/mycode/mysql_debug/server-10.0-galera/mysql_stuff/data --force
/data1/mycode/mysql_debug/server-10.0-galera/cmake-build-debug/sql/mysqld --lc-messages-dir=/data1/mycode/mysql_debug/server-10.0-galera/cmake-build-debug/sql/share/english/.. --bootstrap --basedir=/data1/mycode/mysql_debug/server-10.0-galera/cmake-build-debug --datadir=/data1/mycode/mysql_debug/server-10.0-galera/mysql_stuff/data2 --log-warnings=0 --loose-skip-ndbcluster --max_allowed_packet=8M --net_buffer_length=16K
腳本斷點(diǎn)追蹤 mysql實(shí)例初始化過程
/data1/mycode/mysql_debug/server-10.0-galera# /bin/bash -x ./scripts/mysql_install_db.sh --srcdir=. --ldata=/data1/mycode/mysql_debug/server-10.0-galera/mysql_stuff/data2 --force
cmake 設(shè)置參數(shù) 編譯mysql 代碼
cmake 參數(shù)
-DCMAKE_INSTALL_PREFIX=/data1/mycode/mysql_debug/mysql-8.0.18/mysql_stuff/install -DMYSQL_DATADIR=/data1/mycode/mysql_debug/mysql-8.0.18/mysql_stuff/data -DSYSCONFDIR=/data1/mycode/mysql_debug/mysql-8.0.18/mysql_stuff/etc -DMYSQL_UNIX_ADDR=/data1/mycode/mysql_debug/mysql-8.0.18/mysql_stuff/mysql.sock -DMYSQL_TCP_PORT=3307 -DENABLED_LOCAL_INFILE=1 -DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_general_ci -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_EMBEDDED_SERVER=1 -DWITH_DEBUG=1 -DWITH_BOOST=/data1/mycode/mysql_debug/mysql-8.0.18/boost -DDOWNLOAD_BOOST_TIMEOUT=60000 -DFORCE_INSOURCE_BUILD=1 -DWITH_EMBEDDED_SERVER=1
編譯mysql
clion debug 模式啟動 mysqd
mysqld參數(shù):
--defaults-file=/data1/mycode/mysql_debug/mysql-8.0.18/mysql_stuff/etc/my3311.cnf --user=mysql --basedir=/data1/mycode/mysql_debug/mysql-8.0.18/mysql_stuff/install --datadir=/data1/mycode/mysql_debug/mysql-8.0.18/mysql_stuff/data
登錄實(shí)例
./cmake-build-debug/runtime_output_directory/mysql -uroot -proot -S /data1/mycode/mysql_debug/mysql-8.0.18/mysql_stuff/data/mysql.sock
命令行編譯mysql代碼
下載mysql8源碼
git clone https://github.com/mysql/mysql-server.git
內(nèi)部編譯
cd mysql-server
mkdir build
cd build
cmake .. \
-DCMAKE_INSTALL_PREFIX=/data1/mycode/mysql_debug/mysql_stuff/install \
-DMYSQL_DATADIR=/data1/mycode/mysql_debug/mysql_stuff/data \
-DSYSCONFDIR=/data1/mycode/mysql_debug/mysql_stuff/etc \
-DMYSQL_UNIX_ADDR=/data1/mycode/mysql_debug/mysql_stuff/mysql.sock \
-DMYSQL_TCP_PORT=3307 \
-DENABLED_LOCAL_INFILE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_general_ci \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DWITH_EMBEDDED_SERVER=1 \
-DWITH_DEBUG=1 \
-DDOWNLOAD_BOOST=1 -DWITH_BOOST=/data1/mycode/mysql_debug/mysql-server/ \
-DDOWNLOAD_BOOST_TIMEOUT=60000 \
-DFORCE_INSOURCE_BUILD=1 \
-DWITH_EMBEDDED_SERVER=1
報錯及解決
報錯:
CMake Warning at cmake/bison.cmake:28 (MESSAGE):
No bison found!!
Call Stack (most recent call first):
sql/CMakeLists.txt:1109 (INCLUDE)
CMake Error at sql/CMakeLists.txt:1128 (MESSAGE):
Cannot find /data1/mycode/mysql_debug/mysql-server/sql/sql_yacc.h
-- Configuring incomplete, errors occurred!
See also "/data1/mycode/mysql_debug/mysql-server/CMakeFiles/CMakeOutput.log".
See also "/data1/mycode/mysql_debug/mysql-server/CMakeFiles/CMakeError.log".
解決:安裝bison(apt install bison)
報錯:
-- Library mysqlclient depends on OSLIBS -lpthread;m;rt;/usr/lib/x86_64-linux-gnu/libssl.so;/usr/lib/x86_64-linux-gnu/libcrypto.so;dl
-- MERGE_CONVENIENCE_LIBRARIES TARGET mysqlclient
-- MERGE_CONVENIENCE_LIBRARIES LIBS clientlib;mytime;strings;vio;mysys;zlib;zstd
-- Checking for module 'libtirpc'
-- No package 'libtirpc' found
-- Checking for module 'libtirpc'
-- No package 'libtirpc' found
-- RPC_INCLUDE_DIRS /usr/include
-- MYSQLX - Text log of protobuf messages enabled
-- MYSQLX - Enabled debug traces
-- LINK_FLAGS for mysqld -Wl,-rpath,'$ORIGIN/../lib/private'
-- Found BISON: /usr/bin/bison (found version "3.0.4")
CMake Error at sql/CMakeLists.txt:1128 (MESSAGE):
Cannot find /data1/mycode/mysql_debug/mysql-server/sql/sql_yacc.h
解決:
apt-get install -y libtirpc-dev
安裝依賴:
apt install build-essential cmake bison libncurses5-dev libssl-dev pkg-config
執(zhí)行make
make -j4 && make install
修改 mysql 安裝目錄和數(shù)據(jù)目錄權(quán)限
chown -R mysql:mysql /data1/mycode/mysql_debug/mysql_stuff/install
初始化實(shí)例
/data1/mycode/mysql_debug/mysql_stuff/install/bin/mysqld --initialize --basedir=/data1/mycode/mysql_debug/mysql_stuff/install --datadir=/data1/mycode/mysql_debug/mysql_stuff/data --user=mysql
更改 auto.cnf
由于組復(fù)制嚴(yán)重依賴gtid,所以要修改gtid后8位,保證其不重復(fù)
eg:server-uuid=9236899a-177b-11e8-9599-fa16【4位ip后兩段(不夠4位用0補(bǔ)齊),4位端口號】
啟動實(shí)例
/data1/mycode/mysql_debug/mysql_stuff/install/bin/mysqld_safe --defaults-file=/data1/mycode/mysql_debug/mysql_stuff/etc/my3311.cnf --user=mysql --basedir=/data1/mycode/mysql_debug/mysql_stuff/install --datadir=/data1/mycode/mysql_debug/mysql_stuff/data
登錄實(shí)例
#初次登錄實(shí)例琼富,密碼在error log 中:
/data1/mycode/mysql_debug/mysql_stuff/install/bin/mysql -uroot -pNliKg5.Iqa.K -S /data1/mycode/mysql_debug/mysql_stuff/data/mysql.sock
set password = 'devin';
/data1/mycode/mysql_debug/mysql_stuff/install/bin/mysql -uroot -pdevin -S /data1/mycode/mysql_debug/mysql_stuff/data/mysql.sock