-
下载源码
源码地址:https://github.com/mysql/mysql-server. Mac安装环境mysql版本:v8.0.31
-
环境搭建
- 安装brew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)" - 安装vscode
- 安装cmake
brew install cmake - 安装boost
https://www.boost.org/users/history/version_1_77_0.html
wget https://boostorg.jfrog.io/artifactory/main/release/1.77.0/source/boost_1_77_0.tar.gz
解压 & 拷贝到mysql-server项目: cp -r boost_1_77_0 mysql-server/boost不同的版本对于boost的版本要求不一样
- 安装brew
-
vscode
- 安装扩展:C/C++、C/C++ Clang Command Adapter、CodeLLDB、CMake Tools
- 配置编译
mkdir -p cmake-build-debug/{data,etc}
.vscode.settings.json{ "cmake.buildBeforeRun": true, "cmake.buildDirectory": "${workspaceFolder}/cmake-build-debug/build", "cmake.configureSettings": { "WITH_DEBUG": "1", "CMAKE_INSTALL_PREFIX": "${workspaceFolder}/cmake-build-debug", "MYSQL_DATADIR": "${workspaceFolder}/cmake-build-debug/data", "SYSCONFDIR": "${workspaceFolder}/cmake-build-debug/etc", "MYSQL_TCP_PORT": "3307", "MYSQL_UNIX_ADDR": "${workspaceFolder}/cmake-build-debug/data/mysql-debug.sock", "WITH_BOOST": "${workspaceFolder}/boost", "DOWNLOAD_BOOST": "1", "DOWNLOAD_BOOST_TIMEOUT": "600" }, "git.ignoreLimitWarning": true }
-
编译
image.png
image.png
-
初始化数据库
cat > etc/my.cnf <<EOF
[mysqld]
port=3307
socket=mysql.sock
innodb_file_per_table=1
EOF
cmake-build-debug/build/runtime_output_directory/mysqld --initialize-insecure
- 配置Debug
mkdir .vscode.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/client/mysql", "args": [ "-uroot", "-P3307", "-h127.0.0.1" ], "cwd": "${workspaceFolder}" } ] }
debug运行
参考:
网友评论