#ifdef _WIN32
int win_main(int argc, char **argv)
#else
int mysqld_main(int argc, char **argv)
#endif
{
#zs#
Perform basic thread library and malloc initialization,
to be able to read defaults files and parse options.
#fzs#
my_progname= argv[0]; #zs#注: 记下mysql进程名#fzs#
#ifndef _WIN32
#ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
pre_initialize_performance_schema();
#endif #zs#WITH_PERFSCHEMA_STORAGE_ENGINE #fzs#
// For windows, my_init() is called from the win specific mysqld_main
if (my_init()) // init my_sys library & pthreads
{
sql_print_error("my_init() failed.");
flush_error_log_messages();
return 1;
}
#endif #zs# _WIN32 #fzs#
orig_argc= argc;
orig_argv= argv;
my_getopt_use_args_separator= TRUE;
my_defaults_read_login_file= FALSE;
#zs#注: 这里是去读配置文件里的启动项,读的时候还带入了argv ,应该是argv优行,#fzs#
if (load_defaults(MYSQL_CONFIG_NAME, load_default_groups, &argc, &argv))
{
flush_error_log_messages();
return 1;
}
my_getopt_use_args_separator= FALSE;
defaults_argc= argc;
defaults_argv= argv;
remaining_argc= argc;
remaining_argv= argv;
#zs# Must be initialized early for comparison of options name #fzs#
system_charset_info= &my_charset_utf8_general_ci;
#zs# Write mysys error messages to the error log. #fzs#
local_message_hook= error_log_print;
int ho_error;
#ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
#zs#
Initialize the array of performance schema instrument configurations.
#fzs#
init_pfs_instrument_array();
#endif #zs# WITH_PERFSCHEMA_STORAGE_ENGINE #fzs#
#zs#注: 这里跟过去发现还是在处理启动变量#fzs#
ho_error= handle_early_options();
#if !defined(_WIN32) && !defined(EMBEDDED_LIBRARY)
if (opt_bootstrap && opt_daemonize)
{
fprintf(stderr, "Bootstrap and daemon options are incompatible.n");
exit(MYSQLD_ABORT_EXIT);
}
if (opt_daemonize && log_error_dest == disabled_my_option &&
(isatty(STDOUT_FILENO) || isatty(STDERR_FILENO)))
{
fprintf(stderr, "Please enable --log-error option or set appropriate "
"redirections for standard output and/or standard error "
"in daemon mode.n");
exit(MYSQLD_ABORT_EXIT);
}
if (opt_daemonize)
{
if (chdir("/") < 0)
{
fprintf(stderr, "Cannot change to root director: %sn",
strerror(errno));
exit(MYSQLD_ABORT_EXIT);
}
if ((pipe_write_fd= mysqld::runtime::mysqld_daemonize()) < 0)
{
fprintf(stderr, "mysqld_daemonize failed n");
exit(MYSQLD_ABORT_EXIT);
}
}
#endif
#zs#注: 还是在处理启动变量。。。#fzs#
init_sql_statement_names();
sys_var_init();
ulong requested_open_files;
adjust_related_options(&requested_open_files);
#ifdef WITH_PERFSCHEMA_STORAGE_ENGINE
if (ho_error == 0)
{
if (!opt_help && !opt_bootstrap)
{
#zs# Add sizing hints from the server sizing parameters. #fzs#
pfs_param.m_hints.m_table_definition_cache= table_def_size;
pfs_param.m_hints.m_table_open_cache= table_cache_size;
pfs_param.m_hints.m_max_connections= max_connections;
pfs_param.m_hints.m_open_files_limit= requested_open_files;
pfs_param.m_hints.m_max_prepared_stmt_count= max_prepared_stmt_count;
PSI_hook= initialize_performance_schema(&pfs_param);
if (PSI_hook == NULL && pfs_param.m_enabled)
{
pfs_param.m_enabled= false;
sql_print_warning("Performance schema disabled (reason: init failed).");
}
}
}
#else
#zs#
Other provider of the instrumentation interface should
initialize PSI_hook here:
- HAVE_PSI_INTERFACE is for the instrumentation interface
- WITH_PERFSCHEMA_STORAGE_ENGINE is for one implementation
of the interface,
but there could be alternate implementations, which is why
these two defines are kept separate.
#fzs#
#endif #zs# WITH_PERFSCHEMA_STORAGE_ENGINE #fzs#
#ifdef HAVE_PSI_INTERFACE
#zs#
Obtain the current performance schema instrumentation interface,
if available.
#fzs#
if (PSI_hook)
{
PSI *psi_server= (PSI*) PSI_hook->get_interface(PSI_CURRENT_VERSION);
if (likely(psi_server != NULL))
{
set_psi_server(psi_server);
#zs#
Now that we have parsed the command line arguments, and have initialized
the performance schema itself, the next step is to register all the
server instruments.
#fzs#
init_server_psi_keys();
#zs# Instrument the main thread #fzs#
PSI_thread *psi= PSI_THREAD_CALL(new_thread)(key_thread_main, NULL, 0);
PSI_THREAD_CALL(set_thread_os_id)(psi);
PSI_THREAD_CALL(set_thread)(psi);
#zs#
Now that some instrumentation is in place,
recreate objects which were initialised early,
so that they