2021-03-24 mysql8调试环境搭建

2021-03-24  本文已影响0人  5A风景区

clion mysql调试环境搭建

下载代码

git clone https://github.com/mysql/mysql-server.git

使用clion搭建调试环境

因为clion自带cmake项目,所以搭建不需要额外操作,只需要open 项目就好
#mysqld 参数:
--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实例

/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

脚本断点追踪 mysql实例初始化过程

/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 设置参数 编译mysql 代码

cmake 参数

-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
image.png

编译mysql

image.png

clion debug 模式启动 mysqd

mysqld参数:
--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
image.png

登录实例

./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

内部编译

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

执行make

make -j4 && make install

修改 mysql 安装目录和数据目录权限

chown -R mysql:mysql /data1/mycode/mysql_debug/mysql_stuff/install

初始化实例

/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

由于组复制严重依赖gtid,所以要修改gtid后8位,保证其不重复
eg:server-uuid=9236899a-177b-11e8-9599-fa16【4位ip后两段(不够4位用0补齐),4位端口号】

启动实例

/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

登录实例

#初次登录实例,密码在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
上一篇下一篇

猜你喜欢

热点阅读