MySQL Startup Principle Analysis

Source: Internet
Author: User
Tags syslog

Introduction

This article mainly from the view of the MySQL startup command code to learn more about the MySQL startup process, the content is more conceptual knowledge; Understanding the MySQL startup principle is essential to familiarize with MySQL, three ways to start the MySQL service are: 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 launcher is the Mysql.server,mysql.server program that uses two programs and a function, namely My_print_defaults, Myslqd_safe, and Parse_server_ Arguments

    • My_print_defaults: Reads the MY.CNF configuration file, the output parameter is passed to Parse_server_arguments, and the program reads only the parameters in [mysqld] in my.cnf.
    • Parse_server_arguments: This function handles my_print_defaults passed parameter assignment to--basedir 、--datadir 、--pid-file 、--server-startup-timeout
    • Myslqd_safe:mysqld_safe Program calls MYSQLD program to start MySQL service

Mysql.server

Parse_server_arguments

Viewing the MySQL process information you can see that the parameters--datedir and--pid-file are assigned first through Mysql.server, and These parameters are read from the my.cnf file [mysqld] section. And the values of these two parameters are not overridden by the parameters in the Mysqld_safe program. But the other parameter values in the MY.CNF if [mysqld] and [Mysqld_safe] are the same, the Mysqld_safe is the main, the--open-files-limit is the illustrative example.

Mysqld_safe

In the old version Mysqld_safe is the main starting mode, and the parameters are also very many, for the multi-instance server needs to use the Mysqld_safe to start. Mysqld_safe will invoke the MYSQLD program to start the MySQL service, and Mysqld_safe will read the configuration parameter values in MY.CNF to start the MySQL service. The Mysqld_safe itself has some startup parameters and these boot parameters take precedence over the corresponding parameters in the configuration file.

Mysqld_safe--help

--no-defaults do not read any option file--defaults-file=File configuration Custom default files, if it is multi-instance server here need to configure the corresponding MY.CNF--defaults-extra-file=File file name of the option read except the default file--ledir=DIRECTORY: Specifies the path where the mysqld file resides, and the server for multiple instances can be used to specify the location of the instance separately. --open-files-limit=maximum number of files that LIMIT can open--core-file-size=limit mysqld the size of the kernel file that can be created. Option values are passed to Ulimit-C--timezone=TZ: Sets the TZ time zone environment variable for the given option value. Check the legal time zone format from the operating system documentation--malloc-lib=Lib pre-load shared library lib--mysqld=FILE The name of the server program that you want to start (in the Ledir directory).  The default is Mysqld, which can also be a different name. --mysqld-version=version If you use--mysqld-version =max,mysqld_safe to start the Mysqld-max program in the Ledir directory. If--mysqld-the parameter for version is empty, and Mysqld_safe uses the mysqld in the directory. --nice=Nice uses the Nice program to set the MYSQLD scheduling priority based on the given value. --plugin-dir=dir Configuring the plugin path for 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 to process parameters in a Mysqld_safe program

parse_arguments () {# We need to pass arguments through to the serverifWe don'T# handle them here.  So, we collect unrecognized options (passed in # the command line) into the args variable. Pick_args=ifTest" $"= pick-args-from-ARGV then Pick_args=1shift fi forArg Do# The parameter after"=", or the whole $argifno match Val= ' echo"$arg"| Sed-e's;^--[^=]*=;;'' # what's Before "=", or the whole $arg if no matchOptname= ' 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" inch# theseGetpassed 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 beenSet incha [Mysqld_safe] section of MY.CNF # They is added to mysqld command line toOverrideSettings frommy.cnf--log-error=*) err_log="$val" ;; --port=*) mysql_tcp_port="$val" ;; --socket=*) mysql_unix_port="$val" ;; # Mysqld_safe-specific Options-must beSet inchMY.CNF ([Mysqld_safe])! --core-file-size=*) core_file_size="$val" ;; --ledir=*) ledir="$val" ;; --malloc-lib=*) Set_malloc_lib"$val" ;; --mysqld=*) mysqld="$val" ;; --mysqld-version=*)        ifTest-n"$val"Then MYSQLD="mysqld-$val"plugin_variant="/$val"        ElseMYSQLD="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;; *)        ifTest-n"$pick _args"Then Append_arg_to_args"$arg"fi;; Esac done}

Start with Mysqd_safe

Viewing the MySQL process information you can see that after starting the MySQL service through Mysqld_safe, Myslqd_safe will read the configuration of the MY.CNF configuration file if "mysqld" and "Mysqld_safe" in the configuration file The same parameters are configured to [Mysqld_safe], so you will see that--pid-file is also based on [Mysqld_safe] in the My.cnfa file.

Mysqld

Run the MYSQLD program directly also can start the MySQL service, MYSQLD will use the default configuration to start, for multi-instance MySQL Use this method is not good implementation.

Summary

In the current new version is not recommended in [Mysqld_safe] parameter configuration, the corresponding multi-instance server can be started by Mysqld_safe to specify a different instance of the path and configuration file to start, need to use the----defaults-file 、-- Ledir two parameters to start, from the start of the code can be seen in the MySQL startup to use the two key parameters--datadir--pid-file, so why often when you start and close the MySQL when prompted to find the PID.

Note:

pursuer.chen

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

This site all the essays are original, welcome to reprint, but reprint must indicate the source of the article, and at the beginning of the article clearly give the link.

Welcome to the exchange of discussions

MySQL Startup Principle Analysis

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.