MySQL学习笔记——MySQL5.7的启动过程(一)

MySQL的启动函数在 sql/main.cc 文件中。
main.cc:

extern int mysqld_main(int argc, char **argv);

int main(int argc, char **argv)
{
  return mysqld_main(argc, argv);
}

主函数中只进行了调用mysqld_main函数这么一个操作。
从这个函数开始到结束,就完成了mysqld的启动操作。

mysqld_main函数位于 sql/mysqld.cc 文件内,其中的重要操作如下:
处理配置文件及启动参数等
第4442至4446行:

  if (load_defaults(MYSQL_CONFIG_NAME, load_default_groups, &argc, &argv))
  {
    flush_error_log_messages();
    return 1;
  }

继续处理参数变量
第4468行:

ho_error= handle_early_options();

第4576至4577行:

  /* Initialize audit interface globals. Audit plugins are inited later. */
  mysql_audit_initialize();

日志系统初始化
第4583至4587行:

  /*
    Perform basic query log initialization. Should be called after
    MY_INIT, as it initializes mutexes.
  */
  query_logger.init();

初始化很多系统内部变量
第4608至4609行:

  if (init_common_variables())
    unireg_abort(MYSQLD_ABORT_EXIT);        // Will do exit

信号系统初始化
第4611行:

  my_init_signals();

核心模块启动,包括存储引擎等
第4766至4767行:

  if (init_server_components())
    unireg_abort(MYSQLD_ABORT_EXIT);

第4927至4930行:

  if (init_ssl())
    unireg_abort(MYSQLD_ABORT_EXIT);
  if (network_init())
    unireg_abort(MYSQLD_ABORT_EXIT);

终端重定向处理
未找到:

扫描二维码关注公众号,回复: 3695930 查看本文章
reopen_fstreams();

网络系统初始化
第4929至4930行:

  if (network_init())
    unireg_abort(MYSQLD_ABORT_EXIT);

创建信号句柄
第5031至5038行:

#ifndef _WIN32
  //  Start signal handler thread.
  start_signal_handler();
#endif

  if (opt_bootstrap)
  {
    start_processing_signals();

状态变量初始化
第4988行:

  init_status_vars();

Binlog相关检查初始化
第4993至5009行:

  check_binlog_cache_size(NULL);
  check_binlog_stmt_cache_size(NULL);

  binlog_unsafe_map_init();

  /* If running with bootstrap, do not start replication. */
  if (!opt_bootstrap)
  {
    // Make @@slave_skip_errors show the nice human-readable value.
    set_slave_skip_errors(&opt_slave_skip_errors);

    /*
      init_slave() must be called after the thread keys are created.
    */
    if (server_id != 0)
      init_slave(); /* Ignoring errors while configuring replication. */
  }

创建关闭线程
第5059行:

  create_shutdown_thread();

启动句柄管理
第5061行:

  start_handle_manager();

服务监听线程创建
未找到:

handle_connections_sockets();

服务监听线程创建
未找到:

handle_connections_sockets();

从这里开始,服务器启动线程一直等待,知道shutdown后,继续向下执行
wait until cleanup is done ...
未找到:

mysql_mutex_lock(&LOCK_thread_count);
while (!ready_to_exit) 
    mysql_cond_wait(&COND_thread_count, &LOCK_thread_count);
mysqld_mutex_unlock(&LOCK_thread_count);

第5195至5196行:

clean_up(1);
mysqld_exit(0);

猜你喜欢

转载自www.cnblogs.com/zifeiy/p/9840253.html
今日推荐