代碼分析基于最新的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。-
http://www.linuxidc.com/Linux/2012-03/56277.htm 詳細情況請閱讀我博客里的這篇文章。
對于以HAVE_前綴的的宏,另有如下文章闡述:
http://www.linuxidc.com/Linux/2012-03/56278.htm 這里介紹了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 源代碼的目錄結構 :(以下來自官方文檔)
/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.
本文出自:億恩科技【www.laynepeng.cn】
服務器租用/服務器托管中國五強!虛擬主機域名注冊頂級提供商!15年品質保障!--億恩科技[ENKJ.COM]
|