配置环境
CentOS7.8
默认的 gcc,cmake比较老了,需要安装新的
安装gcc:
1
2
3
4
5
|
sudo yum install centos-release-scl
sudo yum install devtoolset-11-gcc*
scl enable devtoolset-11 bash
which gcc
gcc --version
|
安装cmake
1
2
3
4
5
|
wget https://cmake.org/files/v3.15/cmake-3.15.7.tar.gz
./bootstrap --prefix=usr
gmake
make install
cmake --version
|
安装 vscode
配置远程 ssh环境
如果远程机器不能连外网,需要从vscode官网,下载对应的插件
我装了这么几个插件:
- ms-vscode.cmake-tools-1.13.25.vsix
- [email protected]
- ms-vscode.cpptools-extension-pack-1.3.0.vsix
- ms-vscode.cpptools-themes-2.0.0.vsix
- twxs.cmake-0.0.17.vsix
编译MySQL
下载源码包:
1
|
https://ftp.ntu.edu.tw/MySQL/Downloads/MySQL-8.0/mysql-boost-8.0.28.tar.gz
|
新建 .vscode/settings.json,因为mysql引入了boost,需要让vscode找到这个框架
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
{
"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": "0",
"DOWNLOAD_BOOST_TIMEOUT": "600"
}
}
|
点下面的 build 就可以了,大概需要20-30分钟吧,根据机器性能而定
编译时可能会遇到一些错误:
Curses library not found. Please install appropriate package
yum -y install ncurses-devel 解决
Please install the appropriate openssl developer package
yum -y install openssl-devel 解决
cmake执行时可能会报这样的警告,可以通过,执行安装下就行了
[cmake] Cannot find development libraries. You need to install the required
[cmake] packages:
[cmake]
[cmake] Debian/Ubuntu: apt install libudev-dev
[cmake] RedHat/Fedora/Oracle Linux: yum install libudev-devel
[cmake] SuSE: zypper install libudev-deve
编译后的 mysql在这里:
1
|
/data1/mysql/mysql-8.0.28/cmake-build-debug/build/runtime_output_directory
|
里面有一堆二进制文件,其中就包括mysqld
在 runtime_output_directory 目录下新建一个 my.cnf 文件
[mysqld]
port=3307
socket=mysql.sock
innodb_file_per_table=1
log_bin = on
server-id = 10086
binlog_format = ROW
初始化
1
|
mysqld --defaults-file=etc/my.cnf --initialize-insecure
|
初始化后的数据目录在这里:
1
|
/data1/mysql/mysql-8.0.28/cmake-build-debug/build/data
|
配置.vscode/launch.json
,将mysqld
交给 vscode 启动
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
{
"version": "0.2.0",
"configurations": [
{
"type": "cppdbg",
"request": "launch",
"name": "Debug mysqld",
"program": "${workspaceFolder}/cmake-build-debug/build/runtime_output_directory/mysqld",
"args": [
"--defaults-file=${workspaceFolder}/cmake-build-debug/build/runtime_output_directory/etc/my.cnf",
"--debug",
"--user=root"
],
"cwd": "${workspaceFolder}"
},
{
"type": "cppdbg",
"request": "launch",
"name": "Debug mysql",
"program": "${workspaceFolder}/cmake-build-debug/build/client/mysql",
"args": [
"-uroot",
"-P3307",
"-h127.0.0.1"
],
"cwd": "${workspaceFolder}"
}
]
}
|
启动
点击debug按钮直接启动就行了,启动完后的堆栈信息如下:
服务端的连接方式,貌似远程用 mysql 工具连接还有问题
1
|
./mysql -uroot -S ../data/mysql.sock
|
输入 version后的结果:
1
2
3
4
5
6
7
|
SELECT version();
+--------------+
| version() |
+--------------+
| 8.0.28-debug |
+--------------+
1 row in set (0.00 sec)
|
参考