Get the App
SLTechnology News&Howtos  ›  Database  › 

The order and startup mode of reading configuration files by MySQL as well as the startup principle

Shulou Source: shulou.com Published: 2022-05-31 18:53:46 09月30日 Update

This article mainly explains "the order and startup mode of MySQL reading configuration files as well as the startup principle". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "the order and startup mode of MySQL reading configuration files as well as the startup principle".

I. the order in which MySQL reads configuration files

Reading order: / etc/my.cnf > / etc/mysql/my.cnf > / usr/etc/my.cnf > ~ / .my.cnf

Command verification:

[root@mysql ~] # mysql-- verbose-- help | grep my.cnf

Order of preference, my.cnf, $MYSQL_TCP_PORT

/ etc/my.cnf / etc/mysql/my.cnf / usr/etc/my.cnf ~ / .my.cnf

II. MySQL startup mode

MySQL is usually started in three ways: mysqld, mysqld_safe, and mysqld_multi (mainly used for multi-instance startup)

The relationship in three ways:

First of all, when we start using service mysqld start or / etc/init.d/mysqld start, we actually use the script mysql.server, which calls mysqld_safe by default to start mysqld, so usually when we check the process after starting mysql, we will find that there are two processes, mysqld and mysqld_safe. These two methods are usually launched in a single instance, but you can also use mysqld to launch multiple instances. While mysqld_multi is used to start multiple instances, it also starts mysql by calling mysqld_safe and mysqld first.

Third, the startup principle of MySQL

The default mysql service launcher is the mysql.server,mysql.server program, which mainly uses two programs and a function, which are my_print_defaults, myslqd_safe and parse_server_arguments.

1. My_print_defaults: read the my.cnf configuration file and pass the output parameters to parse_server_arguments. The program only reads the parameters in [mysqld] in my.cnf.

2. Parse_server_arguments: this function handles the parameter assignment passed by my_print_defaults to-- basedir,-- datadir,-- pid-file,-- server-startup-timeout.

3. The myslqd_safe:mysqld_safe program calls the mysqld program to start the mysql service, and [mysqld_safe] overrides the parameters in the mysqld section.

4. Mysqld_multi will read the parameters under [mysqld_muti] and [mysqldN] in the configuration file. If N needs an integer, it is recommended to use the port number. The configuration of this part will override the configuration in the [mysqld] section.

5. When the mysqld process dies, the mysqld_safe process detects and restarts the mysqld.

At this point, I believe that everyone has a deeper understanding of the "MySQL read configuration file sequence and startup mode as well as the startup principle", might as well come to the actual operation! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Mode configuration file program order parameter principle instance process time part two content function script learning service practical deeper interest Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology macOS Docker MySQL MariaDB