Configuration file MySQL source code interpretation

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

To study mysql, the best resources than the source code, so I am going to the source code to understand the MySQL bit by bit. Set up MySQL debugging environment is very simple, from the official download the MySQL source code, using cmake tools to generate the project to. In order to facilitate debugging, but also because of the intuitive vs debugging, my source is below the windows platform, here entered.

    In the environment of VS, select the mysqld project, direct start debugging and running, this time I did not specify any configuration files, but the program is still running, then the program should be able to use the default configuration file. First need to identify two problems, procedures for the configuration file in a directory on what, in what order to find. Through debugging, the program will first collected the windows system directory, the C:\ root directory, executing code where the parent directory, if the configuration of the MYSQL_HOME environment variable, this directory will be collected, and then find the my.ini file in the directory, this involves the main interfaces are my_load_defaults and search_default_file.

But the actual situation is, these folders without any a configuration file, that even when mysqld is started, a configuration file is not to obtain information, but also can start successfully, then the default value must be written in the code inside the dead. Now we find these parameters to default values to the code, and how they are initialized. In, we see the definition of the global variable global_system_variables, the parameter is a variable, the variable contains most of the MySQL systems, the next step is to look at the global variable when it is initialized. In VS, we can set a data breakpoint, through a data breakpoint we can know the specific memory address is when to be changed. We analyze the max_connections, the address data breakpoints, have a look when it was changed, it really is changed, the stack as shown below:

Stack shows the initialization process, analyzes each function that can know the initialization logic.

The code as shown below:

This shows that the global variables and the corresponding value is one one. By tracking variables, find the all_sys_vars variable, the variable is a structure, including two pointer, the initialization values for the NULL, tracking the list to find the answer to the question. In the sys_vars.h header files, we find the all_sys_vars variable shadow, track down sb. by following clues, in the file, see a lot of static objects, can be seen from the name, these objects and variables have all kinds of connections with contact. For example, a Sys_max_connections object is defined as follows:

It is understood, by passing the address of max_connections, established with the object sys_var relation, and all sys_var objects through the list object all_sys_vars management. So far, we already know the MySQL system variable value initialization sequence of events. Through the --defaults-file we can specify the configuration file. The basic logic is, read the default parameter values, use the configuration file on the cover, the configuration file value effect. The following report of several main classes and interfaces:

My_search_option_files (search for files),
Search_default_file_with_ext (read the configuration file contents),
Handle_default_option (each line)
Getopt_compare_strings (to find a match, set specific parameter values)
Insert_dynamic (variable into the list)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Andrew at December 17, 2013 - 7:52 AM