前准备
vscode(安装remote dev插件)、mysql源码、c/c++、安装cmake、安装gcc
mysql源码:git clone https://github.com/mysql/mysql-server.git
cmake安装:sudo yum install cmake3
查看cmake版本:cmake --version
安装gcc:sudo yum install gcc
在计算云上编译mysql
1、配置(进入mysql源码文件目录)
创建编译目录
mkdir -p cmake-build-debug/{data\etc}
cd cmake-build-debug
配置
cmake .. \
-B./build \
-DWITH_DEBUG=1 \
-DCMAKE_INSTALL_PREFIX=. \
-DMYSQL_DATADIR=./data \
-DSYSCONFDIR=./etc \
-DMYSQL_TCP_PORT=3307 \
-DMYSQL_UNIX_ADDR=mysql-debug.sock \
-DWITH_BOOST=../boost \
-DDOWNLOAD_BOOST=1 \
-DDOWNLOAD_BOOST_TIMEOUT=60000
这一步遇到的问题总结:
1、 遇到Error: Unable to find a match: gcc-toolset-12-gcc gcc-toolset-12-gcc-c++ gcc-toolset-12-binutils gcc-toolset-12-annobin-annocheck gcc-toolset-12-annobin-plugin-gcc 需要更换yum源。
2.CMake Error: The source directory “/mysql” does not appear to contain CMakeLists.txt.目录需要跳到CMakeLists.txt.上级。
3、Cannot find RPC development libraries. You need to install the required
packages:
Debian/Ubuntu: apt install libtirpc-dev
RedHat/Fedora/Oracle Linux: yum install libtirpc-devel
SuSE: zypper install glibc-devel
按照步骤安装yum install libtirpc-devel
编译
# 查看有多少核
cat /proc/cpuinfo |grep "core" |wc -l
# 替换你自己计算云核数,我这里是32核。
cmake --build build --target mysqld -j 32
初始化数据库
mysql配置文件写道这个目录下 cmake-build-debug/etc/my.cnf
cat > etc/my.cnf <<EOF
[mysqld]
port=3307
user=root
socket=mysql.sock
innodb_file_per_table=1
EOF
初始化数据库
build/runtime_output_directory/mysqld --defaults-file=etc/my.cnf --initialize-insecure
创建文件 .version/launch.json
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Debug mysqld",
"program": "${workspaceFolder}/cmake-build-debug/build/runtime_output_directory/mysqld",
"args": [
"--defaults-file=${workspaceFolder}/cmake-build-debug/etc/my.cnf"
],
"cwd":"${workspaceFolder}"
},
{
"type": "lldb",
"request": "launch",
"name": "Debug mysql",
"program": "${workspaceFolder}/cmake-build-debug/build/data/mysql",
"args": [
"-uroot",
"-P3007",
"-h127.0.0.1"
],
"cwd":"${workspaceFolder}"
}
]
}
点击run and bebug 启动mysqld
最后需要在计算云上安装mysql客户端,正常安装mysql,启动计算云mysql。
1、到mysql bin目录下: mysql -uroot -P3007 -h127.0.0.1
2、或者直接根据bin路径 ,例如:/usr/local/mysql/bin/mysql -uroot -P3307 -h127.0.0.1
3、断点调试;正常写入sql语句,在vscode中bedug
注:要先run后开mysql,结束先退mysql后关vscode中调试,当不小心先关了调试,及时退出计算云mysql,不然当mysql客户端没退出再次开启run and debug时容易出现singal异常,出现异常需要删除cmake-build-debug中build文件,重新配置编译初始化。
## window下vscode连接上远程
连接上远程后进入mysql源码目录, run and debug 创建mysqld文件夹.vscode
标签:gcc,cmake,源码,build,install,mysql,debug,云上 From: https://blog.csdn.net/weixin_43381707/article/details/139198825