• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

MySQL源代码阅读笔记:代码流程

mysql 搞代码 4年前 (2022-01-09) 17次浏览 已收录 0个评论

代码分析基于最新的5.5.21 Mysql服务器的main()在/sql/main.cc,实际的入口点在/sql/mysqld.cc。 我们直接从mysqld_main()开始阅

代码分析基于最新的5.5.21

Mysql服务器的main()在/sql/main.cc,实际的入口点在/sql/mysqld.cc。

我们直接从mysqld_main()开始阅读。

先理解一些比较重要的宏定义:

(1)宏HAVE_NPTL:

这个宏如果打开了会去读一个系统变量LD_ASSUME_KERNEL,并把他赋给一个全局变量ld_assume_kernel_is_set,这个系统变量设置了系统线程的实现模型。linux内核在2.6版本后,缺省的线程模型是NPTL。

详细情况请阅读我博客里的这篇文章。

对于以HAVE_前缀的的宏,另有如下文章阐述:

这里介绍了CMake的相关知识,,通过CMake在影子编译目录的include目录里面生成了my_config.h文件。

my_config.h文件通过my_global.h文件包含到具体的需要使用HAVE_前缀的宏的源文件中。

(2)EMBEDDED_LIBRARY

该宏用于控制 嵌入式库和客户端/服务器版本不同的那部分代码。

Mysql 可以编译为一个libmysqld库(嵌入式服务器),使用嵌入式MySQL服务器库,能够在客户端应用程序中使用具备全部特性的MySQL服务器。

主要优点在于,增加了速度,并使得嵌入式应用程序的管理更简单。嵌入式服务器库是以MySQL的客户端/服务器版本为基础的,采用C/C++语言编写。 其结果是嵌入式服务器也是用C/C++语言编写的。 在其他语言中,嵌入式服务器不可用。

这个宏可以通过CMake配置,

-DWITH_EMBEDDED_SERVER=1 打开这个宏

在plug.cmake函数里有它的定义:

PROPERTIES COMPILE_DEFINITIONS “MYSQL_SERVER;EMBEDDED_LIBRARY”)

整个代码的流程如下:我们讲分更细的文章详细介绍每部分:

Mysql服务器监听:

Mysql 本文来源gaodai$ma#com搞$$代**码网源代码的目录结构 :(以下来自官方文档)

/BUILD The compilation configuration and make files for all platforms supported.
Use this folder for compilation and linking.
/client The MySQL command-line client tool.
/dbug Utilities for use in debugging (see Chapter 5 for more details).
/Docs Documentation for the current release. Linux users should usegenerate-text-files.pl in the support subfolder to generate the documentation. Windows users are provided with a manual.chm file.
/include The base system include files and headers.
/libmysql The C client API used for creating embedded systems. (See Chapter 6 formore details.)
/libmysqld The core server API files. Also used in creating embedded systems.(See Chapter 6 for more details.)
/mysql-test The MySQL system test suite. (See Chapter 4 for more details.)
/mysys The majority of the core operating system API wrappers and helper functions.
/regex A regular expression library. Used in the query optimizer and execution to resolve expressions.
/scripts A set of shell script-based utilities.
/sql The main system code. You should start your exploration from this folder.
/sql-bench A set of benchmarking utilities.
/SSL A set of Secure Socket Layer utilities and definitions.
/storage The MySQL pluggable storage engine source code is located inside this folder. Also included is the storage engine example code. (See Chapter 7 for more details.)
/strings The core string handling wrappers. Use these for all of your string handling needs.
/support-files A set of preconfigured configuration files for compiling with different options.
/tests A set of test programs and test files.
/vio The network and socket layer code.
/zlib Data compression tools.


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:MySQL源代码阅读笔记:代码流程
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址