Abstract
本文会记录如何在macos上使用clion debug mysql源代码.
环境
MACOS, CLION 2019.2
步骤
-
下载源码官方GITHUB , 我clone的 防止代码后续有变化.
-
在clion中Import as new cmake project.
然后默认编译完成后 遇到如下错误:
Make Error at cmake/boost.cmake:104 (MESSAGE):You can download it with -DDOWNLOAD_BOOST=1 -DWITH_BOOST=<directory>This CMake script will look for boost in <directory>. If it is not there,it will download and unpack it (in that directory) for you.You can also download boost manually, fromhttps://dl.bintray.com/boostorg/release/1.70.0/source/boost_1_70_0.tar.gzIf you are inside a firewall, you may need to use an https proxy:export https_proxy=http://example.com:80
-
手动下载boost https://dl.bintray.com/boostorg/release/1.70.0/source/boost_1_70_0.tar.gz
-
在源码目录新建如下目录AbuildDownloaded临时目录, 然后把boost下载的文件放进去.
在AbuildDownloaded新建my.cnf文件内容如下(目录按照自身环境修改, 这里使用了额外的端口33070, 保证不与本地的mysql冲突):
[mysqld]
port=33070
transaction_isolation=READ-COMMITTED
basedir=/Users/edward.gao/work/forked/mysql-server/AbuildDownloaded/
datadir=/Users/edward.gao/work/forked/mysql-server/AbuildDownloaded/datadir
socket=/Users/edward.gao/work/forked/mysql-server/AbuildDownloaded/mysql.sock
[mysql]
sql_mode=ONLY_FULL_GROUP_BY,NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
- 修改cmake配置
添加CMake options 设置boost路径:
-DWITH_BOOST=/Users/edward.gao/work/forked/mysql-server/AbuildDownloaded/
自动编译完成的界面:
- 编译运行mysqld debug模式和配置mysqld启动参数
debug这个main方法:
这一步完成后, 你应该可以看见编译好的mysqld和 debug栏目, 但是启动还有报错:
此时需要, 修改debug模式的启动参数:
--defaults-file=/Users/edward.gao/work/forked/mysql-server/AbuildDownloaded/my.cnf --basedir=/Users/edward.gao/work/forked/mysql-server/AbuildDownloaded --datadir=/Users/edward.gao/work/forked/mysql-server/AbuildDownloaded/datadir --initialize-insecure
初始化完成后, 再删除–initialize-insecure重新debug一次.
运行mysqld完成:
- 测试mysql
需要先生成mysql连接客户端的工具.
执行这个配置debug, 然后folder里面就有了mysql这个命令:
测试mysql 执行如下命令:
./cmake-build-debug/bin/mysql -u root -h 127.0.0.1 -P33070
debug 每个sql语句: