MySQL startup Principle Analysis, mysql Principle Analysis

Source: Internet
Author: User

MySQL startup Principle Analysis, mysql Principle Analysis
Introduction

This article focuses on viewing the MySQL startup command code to learn more about the MySQL startup process. It is important to understand the MySQL startup principle and be familiar with MySQL, there are three ways to start the mysql service: mysql. sever, mysqld, mysqld_safe.

 

My. cnf

[client]socket=/tmp/mysql.sockport=3306[mysqld]#################[base]##########################basedir =/usr/local/mysqldatadir =/data/mysql/innodb_data_home_dir=/data/mysql/innodb_log_group_home_dir=/data/mysql/port =3306user=mysqlpid-file=/data/mysql/mysql.pidsocket =/tmp/mysql.sockdefault_storage_engine=innodbcharacter_set_server=utf8open_files_limit=65535[mysqld_safe]log_error=/usr/local/mysql/log/mysql-error.logpid-file=/usr/local/mysql/log/mysql.pidopen_files_limit=15000

 

Mysql. server

The default mysql Service Startup Program is mysql. server. The mysql. server program mainly uses two programs and one function, namely my_print_defaults, myslqd_safe, and parse_server_arguments.

  • My_print_defaults: Read the my. cnf configuration file and pass the output parameters to parse_server_arguments. The program reads only the parameters in [mysqld] Of my. cnf.
  • Parse_server_arguments: This function processes the parameters passed by my_print_defaults and assigns values to -- basedir, -- datadir, -- pid-file, and -- server-startup-timeout.
  • Myslqd_safe: The mysqld_safe program calls the mysqld program to start the mysql service.

Mysql. server

Parse_server_arguments

 

View the mysql process information. when server is started, values are assigned to the -- datedir and -- pid-file parameters. the cnf file [mysqld] is read, and the values of these two parameters are not overwritten by the values assigned by the parameters in the mysqld_safe program. However, if other parameter values in my. cnf are the same as [mysqld] and [mysqld_safe], mysqld_safe is the primary parameter. -- open-files-limit in the preceding example is the description.

 

Mysqld_safe

In earlier versions, mysqld_safe is the main startup method and has many parameters. For multi-instance servers, mysqld_safe is used for startup. Mysqld_safe calls the mysqld program to start the mysql service, and mysqld_safe reads the configuration parameter values in my. cnf to start the mysql service. Mysqld_safe also has some startup parameters, and these startup parameters take precedence over the corresponding parameters in the configuration file.

Mysqld_safe -- help

-- No-defaults does not read any option file -- defaults-FILE = file to configure the custom default FILE. If it is a multi-instance server, you need to configure it to the corresponding my. cnf -- defaults-extra-file = FILE Option file name read in addition to the default FILE -- ledir = DIRECTORY: Specifies the path of the mysqld file, multiple instances can be used to specify the locations of instances. -- Open-files-limit = maximum number of files that can be opened by LIMIT -- core-file-size = size of the kernel files that can be created by LIMIT mysqld. Option value passed to ulimit-c -- timezone = TZ: Set the TZ time zone environment variable for the given option value. View the valid time zone format from the operating system documentation-malloc-lib = LIB pre-loaded shared library lib -- mysqld = FILE Name of the server program to be started (in the ledir directory ). The default value is mysqld or another name. -- Mysqld-version = VERSION if you use -- mysqld-version = max, mysqld_safe to start the mysqld-max program in the ledir directory. If the -- mysqld-version parameter is null, mysqld_safe uses mysqld in the directory. -- Nice = NICE uses the nice program to set the scheduling priority of mysqld Based on the given value. -- Plugin-dir = DIR: configure the plugin path of the mysql service, /usr/local/mysql/lib/plugin -- skip-kill-mysqld Don't try to kill stray mysqld processes -- syslog Log messages to syslog with 'logger '-- skip-syslog Log messages to error log (default) -- syslog-tag = TAG Pass-t "mysqld-TAG" to 'logger'

 

Pare_arguments Function

This function is a function used in the mysqld_safe program to process parameters. From the code below, you can find out which parameters mysqld_safe mainly processes.

parse_arguments() {  # We only need to pass arguments through to the server if we don't  # handle them here.  So, we collect unrecognized options (passed on  # the command line) into the args variable.  pick_args=  if test "$1" = PICK-ARGS-FROM-ARGV  then    pick_args=1    shift  fi  for arg do    # the parameter after "=", or the whole $arg if no match    val=`echo "$arg" | sed -e 's;^--[^=]*=;;'`    # what's before "=", or the whole $arg if no match    optname=`echo "$arg" | sed -e 's/^\(--[^=]*\)=.*$/\1/'`    # replace "_" by "-" ; mysqld_safe must accept "_" like mysqld does.    optname_subst=`echo "$optname" | sed 's/_/-/g'`    arg=`echo $arg | sed "s/^$optname/$optname_subst/"`    case "$arg" in      # these get passed explicitly to mysqld      --basedir=*) MY_BASEDIR_VERSION="$val" ;;      --datadir=*) DATADIR="$val" ;;      --pid-file=*) pid_file="$val" ;;      --plugin-dir=*) PLUGIN_DIR="$val" ;;      --user=*) user="$val"; SET_USER=1 ;;      # these might have been set in a [mysqld_safe] section of my.cnf      # they are added to mysqld command line to override settings from my.cnf      --log-error=*) err_log="$val" ;;      --port=*) mysql_tcp_port="$val" ;;      --socket=*) mysql_unix_port="$val" ;;      # mysqld_safe-specific options - must be set in my.cnf ([mysqld_safe])!      --core-file-size=*) core_file_size="$val" ;;      --ledir=*) ledir="$val" ;;      --malloc-lib=*) set_malloc_lib "$val" ;;      --mysqld=*) MYSQLD="$val" ;;      --mysqld-version=*)        if test -n "$val"        then          MYSQLD="mysqld-$val"          PLUGIN_VARIANT="/$val"        else          MYSQLD="mysqld"        fi        ;;      --nice=*) niceness="$val" ;;      --open-files-limit=*) open_files="$val" ;;      --open_files_limit=*) open_files="$val" ;;      --skip-kill-mysqld*) KILL_MYSQLD=0 ;;      --syslog) want_syslog=1 ;;      --skip-syslog) want_syslog=0 ;;      --syslog-tag=*) syslog_tag="$val" ;;      --timezone=*) TZ="$val"; export TZ; ;;      --help) usage ;;      *)        if test -n "$pick_args"        then          append_arg_to_args "$arg"        fi        ;;    esac  done}

 

Start with mysqd_safe

View the mysql process information. After mysqld_safe is used to start the mysql service, myslqd_safe will. read the configuration in the cnf configuration file. If [mysqld] and [mysqld_safe] in the configuration file are configured with the same parameters, [mysqld_safe] is used as the primary parameter, so we can see that -- pid-file is also my. in the cnfa file [mysqld_safe.

 

Mysqld

Directly running the mysqld program can also start the mysql service. mysqld will start with the default configuration, which is not easy to implement for mysql with multiple instances.

 

Summary

In the current new version, we do not recommend that you configure parameters in [mysqld_safe, when the server of multiple instances is started, you can use mysqld_safe to specify the path and configuration file of different instances for startup. You need to use the ---- defaults-file and -- ledir parameters to start the instance, from the startup code, we can see the two key parameters used for mysql startup-datadir-pid-file. Why do we often prompt that the pid cannot be found when mysql is started or shut down.

 

 

 

 

Note:

Author: pursuer. chen

Blog: http://www.cnblogs.com/chenmh

All essays on this site are original. You are welcome to repost them. However, you must indicate the source of the article and clearly give the link at the beginning of the article.

Welcome to discussion

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.