MySQL (InnoDB analysis): ---The concept of database and instance, configuration file read at startup, MySQL architecture

One, the concept of database and instance

  • There are two words in the database field that are easy to confuse, namely " databases " and "instance "

Concept of database and instance

  • Database: A collection of physical operating system files or other file types . In the MySQL database, the database file can be a file ending in frm, MYD, MYI, and ibd. When using the NDB engine, the database file may not be a file on the operating system, but a file stored in memory, but the definition remains unchanged
  • Example : MySQL database consists of background threads and a shared memory area . Shared memory can be shared by running background threads. What needs to be kept in mind is that the database instance is really used to manipulate database files
  • In the MySQL database, the relationship between instances and databases is usually one-to-one, that is, one instance corresponds to one database, and one database corresponds to one instance . However, there may be a plurality of database instances using the database is a clustered case conditions
  • MySQL is designed as a single-process multi-threaded architecture database , which is similar to SQL Server, but different from Oracle's multi-process architecture (Oracle's Windows version is also single-process multi-threaded architecture). That is to say, the performance of the MySQL database instance on the system is a process

Demo case

  • Use the mysqld_safe script to start MySQL in the Linux operating system

  • Then use the ps command to view the background process of MySQL. The process number 3039 is the MySQL instance

Second, the configuration file

  • When the instance is started, the MySQL database will read the configuration file and start the database instance according to the parameters of the configuration file
  • Different from Oracle :
    • This is similar to the Oracle parameter file (spfile). The difference is that if there is no parameter file in Oracle, the parameter file will not be found when starting the instance, and the database will fail to start.
    • There may be no configuration file in the MySQL database. In this case, MySQL will start the instance according to the default parameter settings at compile time
  • Under Linux, the configuration file is generally placed under /etc/my.cnf or /etc/mysql/my.cnf
  • Under Windows, the suffix of the configuration file may be .cnf or .ini

See where the configuration file is

①Under Linux system:

mysql --help | grep my.cnf

  • You can see that the MySQL database is read in the order of /etc/my.cnf->/etc/mysql/my.cnf->/usr/local/mysql/etc/my.cnf->~/.my.cnf Profile
  • If several configuration files have the same parameter, MySQL will take the parameter in the last configuration file read as the standard

②Under Windows system :

  • Run the following command under Windows operating system to find the following
mysql --help

Three, the path of the mysql instance

  • The configuration file has a parameter datadir , which specifies the path where the database is located. The path may be different under different operating systems. For example, if you view the MySQL background process in the above figure, you can see that the --datadie parameter is /var/lib/mysql. The user can modify this parameter, and of course this path can also be used

Demonstration description

  • The following environment is Ubuntu 14.04
show variables like 'datadir'\G

Four, MySQL architecture

  • The architecture of the MySQL database is as follows, and the structure diagram is taken from the MySQL official manual

  • MySQL consists of the following parts:
    • Connection pool component
    • Management services and tool components
    • SQL interface components
    • Query Analyzer component
    • Optimizer component
    • Cache component
    • Plug-in storage engine
    • Physical file
  • As you can see from the figure, one of the most important features that distinguishes the MySQL database from other databases is its plug-in table storage engine . The MySQL plug-in storage engine architecture provides a series of standard management and service support. These standards have nothing to do with the storage engine itself, and may be necessary for every database system itself, such as SQL analyzers and optimizers, while the storage engine The realization of the underlying physical structure, each storage engine developer can develop according to his own wishes
  • It is important to note that the storage engine is based on the table, not the database

 

Guess you like

Origin blog.csdn.net/m0_46405589/article/details/113823430