登录
首页 >  数据库 >  MySQL

MySQL 源码阅读 —— macOS CLion 编译调试 MySQL 5.7

来源:SegmentFault

时间:2023-01-29 12:57:02 324浏览 收藏

积累知识,胜过积蓄金银!毕竟在##column_title##开发的过程中,会遇到各种各样的问题,往往都是一些细节知识点还没有掌握好而导致的,因此基础知识点的积累是很重要的。下面本文《MySQL 源码阅读 —— macOS CLion 编译调试 MySQL 5.7》,就带大家讲解一下MySQL、编译、MacOS、源码分析、clion知识点,若是你对本文感兴趣,或者是想搞懂其中某个知识点,就请你继续往下看吧~

macOS + VSCode 版本看这里

环境信息

  • macOS Big Sur 11.5.2
  • CLion 2021.2
  • MySQL 5.7.35
  • CMake 3.21.1
  • openssl 1.1

下载源码

官网下载携带

mv VERSION MYSQL_VERSION
sed -i '' 's|${CMAKE_SOURCE_DIR}/VERSION|${CMAKE_SOURCE_DIR}/MYSQL_VERSION|g' cmake/mysql_version.cmake

具体原因,可参考文章:MySQL 源码 —— 问题 expanded from macro MYSQL_VERSION_MAJOR

配置 CMake

配置 CMake

CMake options 配置如下:

# 为何加`cmake-build-debug`前缀,因为`CLion`中`CMake`的`Build directory`就是`cmake-build-debug`,可自行修改
mkdir -p cmake-build-debug/build_out cmake-build-debug/build_out/data cmake-build-debug/build_out/etc

运行 CMake

方法一:

/Applications/CLion.app/Contents/bin/cmake/mac/bin/cmake -DCMAKE_BUILD_TYPE=Debug -DWITH_DEBUG=1 -DDOWNLOAD_BOOST=1 -DDOWNLOAD_BOOST_TIMEOUT=60000 -DWITH_BOOST=boost -DCMAKE_INSTALL_PREFIX=build_out -DMYSQL_DATADIR=build_out/data -DSYSCONFDIR=build_out/etc -DMYSQL_TCP_PORT=3307 -DMYSQL_UNIX_ADDR=mysql-debug.sock -DCMAKE_DEPENDS_USE_COMPILER=FALSE -G "CodeBlocks - Unix Makefiles" /path/to/mysql-5.7.35

······
-- Configuring done
-- Generating done
-- Build files have been written to: /path/to/mysql-5.7.35/cmake-build-debug

编译 mysqld

点击

====================[ Build | mysqld | Debug ]==================================
/Applications/CLion.app/Contents/bin/cmake/mac/bin/cmake --build /path/to/mysql-5.7.35/cmake-build-debug --target mysqld -- -j 3
[  0%] Built target regex
··· 中间日志省略 ···
[100%] Built target mysqld

Build finished

配置 my.cnf

如有其他定制化配置需要,可添加/修改
[mysqld]
innodb_file_per_table = 1

初始化 mysqld

点击

mysql -uroot -P3307 -h127.0.0.1

也可以通过 Navicat 连接:

Navicat连接

然后在客户端输入一条 SQL,

cmake . -DWITH_BOOST=boost

不带
cmake . \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=

这是 MySQL 建议的构建方式。CMake 会到

wget https://nchc.dl.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz
tar -zxf boost_1_59_0.tar.gz
cmake . \
-DWITH_BOOST=

Warning: define bzero please_use_memset_rather_than_bzero

在构建过程中,可能会报如下 Warning

[ 31%] Building C object storage/myisammrg/CMakeFiles/myisammrg.dir/myrg_records.c.o
In file included from /path/to/mysql-5.7.35/storage/myisam/mi_page.c:25:
In file included from /path/to/mysql-5.7.35/storage/myisam/myisamdef.h:26:
In file included from /path/to/mysql-5.7.35/include/myisam.h:34:
/path/to/mysql-5.7.35/include/m_string.h:32:9: warning: 'bzero' macro redefined [-Wmacro-redefined]
#define bzero please_use_memset_rather_than_bzero
        ^
/Library/Developer/CommandLineTools/SDKs/MacOSX11.3.sdk/usr/include/secure/_strings.h:52:9: note: previous definition is here
#define bzero(dest, ...) \
        ^
In file included from /path/to/mysql-5.7.35/storage/myisammrg/myrg_records.c:24:
In file included from /path/to/mysql-5.7.35/storage/myisammrg/myrg_def.h:25:
In file included from /path/to/mysql-5.7.35/storage/myisammrg/../myisam/myisamdef.h:26:
In file included from /path/to/mysql-5.7.35/include/myisam.h:34:
/path/to/mysql-5.7.35/include/m_string.h:32:9: warning: 'bzero' macro redefined [-Wmacro-redefined]
#define bzero please_use_memset_rather_than_bzero
        ^
/Library/Developer/CommandLineTools/SDKs/MacOSX11.3.sdk/usr/include/secure/_strings.h:52:9: note: previous definition is here
#define bzero(dest, ...) \
        ^
1 warning generated.

/Library/Developer/CommandLineTools/SDKs/MacOSX11.3.sdk/usr/include/secure/_strings.h:52:9: note: previous definition is here

#define bzero(dest, ...) \
        __builtin___memset_chk (dest, 0, __VA_ARGS__, __darwin_obsz0 (dest))
#endif

意思是

/path/to/mysql-5.7.35/include/m_string.h:32:9: warning: 'bzero' macro redefined [-Wmacro-redefined]

#define bzero please_use_memset_rather_than_bzero

mysql
中的宏定义却并非函数代码,反而提示应该用
memset
函数,而非
bzero
函数,此意是提示
MySQL
开发者后续要修改代码了。此处是用 redefined 来提示,并不对实际运行产生影响。在 MySQL 8.0 中已经没了此类提示。

所以,此类 Warning 我们可忽略。

expanded from macro MYSQL_VERSION_MAJOR

参考 MySQL 源码 —— 问题 expanded from macro MYSQL_VERSION_MAJOR

编译 mysql 等工具

此前,我们只编译了

mysqld
服务器这一个软件。但我们需要
mysql
客户端,或
mysqldump
等其他工具时,也可以选择配置其他项,并点击
Build
就可以。

build-mysql

参考资料


感谢您的阅读,觉得内容不错,点个赞吧 😆
原文地址: https://shockerli.net/post/mysql-source-macos-clion-debug-5-7/

本篇关于《MySQL 源码阅读 —— macOS CLion 编译调试 MySQL 5.7》的介绍就到此结束啦,但是学无止境,想要了解学习更多关于数据库的相关知识,请关注golang学习网公众号!

声明:本文转载于:SegmentFault 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>