Chapter 1: Mysql architecture and storage engine

1.1 Define database and instance

What is the difference between database and instance?

A database is a collection of physical operating systems or other forms of files (a database is a collection of files, a collection of data organized according to a certain data model and stored in secondary storage). The database instance is actually used to operate database files (the database instance is a program, a layer of data management software located between the user and the operating system). The Mysql database consists of background threads and a shared memory area. The shared memory can be run Shared by background threads. These two concepts can sometimes be used with each other, but the concepts of the two are completely different. In the Mysql database, instances and databases have a one-to-one correspondence, that is, one instance corresponds to one database, and one database corresponds to one instance. But in the case of a cluster, There may be situations where a database is used by multiple instances. (Mysql is designed as a single-process multi-thread architecture database, and the database instance behaves as a process on the system)

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. The following demonstrates how to see where the mysql database is:

mysql --help | grep my.cnf

Insert image description here
You can see that the Mysql database reads the configuration in the order of /etc/my.cnf -> /ect/mysql/my.cnf -> /usr/local/mysql/etc/my.cnf -> ~/.my.cnf file. If these configuration files are configured with the same parameters, the parameters of the last configuration file will prevail.

1.2 Mysql architecture

The Mysql architecture is as follows:

Insert image description here
The above architecture consists of the following parts:

  • Connection pool component
  • Management services and tools components
  • SQL interface component
  • Query Analyzer Component
  • Optimizer component
  • Cache component
  • Plug-in storage engine
  • physical file

Mysql数据库区别于其他数据库的最重要的一个特点就是其插件式的表存储引擎,存储引擎是基于表的不是基于数据库的

1. 3 Mysql storage engine

The core point of a database is to store data, and data storage cannot avoid dealing with disks. So how and how data is stored is the key to storage. Therefore, the storage engine is equivalent to the engine of data storage, driving data to be stored at the disk level. The capabilities of different storage engines vary greatly.

  • InnoDB storage engine

The conceptual
InnoDB storage engine supports transactions and is designed primarily for online transaction processing (OLTP) applications. It is characterized by row lock design and support for foreign keys . It is the default storage engine of Mysql starting from version 5.5.8.
Features

  1. InnoDB achieves high concurrency by using multi-version concurrency control (MVCC) and implements four isolation levels of the SQL standard, with the default being Repeatable level. At the same time, a strategy called next-key locking is used to avoid phantom reads.
  2. The InnoDB storage engine provides high-performance and high-availability functions such as insertion buffering, secondary writing, adaptive hash indexes, and read-ahead.
  3. For data storage in tables, InnoDB uses an aggregation method, so each table is stored in the order of the primary key. If the primary key is not explicitly specified in the definition of the table, the InnoDB storage engine will generate A 6-byte ROWID as the primary key.
  • MyISAM storage engine

Concept
MyISAM is the default database engine for MySQL (before version 5.5), which was improved from the early ISAM. Although the performance is excellent, it has a disadvantage: it does not support transaction processing.

Features

  1. One distinctive feature of the MyISAM storage engine is that its cache pool only caches index files, not data files.
  2. The MyISAM storage engine table consists of MYD and MYI. MYD is used to store data files and MYI is used to store index files.
  3. MyISAM storage engine table and Mysql database only cache its index files, and the caching of data files is completed by the operating system itself.
  • NDB storage engine

The concept of
NDB storage engine is a cluster storage engine, similar to ORACLE's RAC cluster. Its structural shar nothing cluster architecture can provide high availability.

Features

  1. All data is placed in the memory (non-index data can be placed on the disk starting from 5.1), so the primary key data search is extremely fast, and the database performance can be linearly improved by adding NDB data storage nodes (Data Node), which is highly efficient. Available, high-performance cluster system.
  2. The connection operation of the NDB storage engine is completed at the MYSQL database layer, not in the storage engine. This means that complex join operations require huge network overhead, so the query speed is very slow.

1. 4 FAQ

  • Does Mysql support full-text indexing?

Answer: Support

  • Is the Myslq database fast because it does not support transactions?

Answer: Wrong! Although MySQL's MyISAM storage engine does not support transactions, InnoDB does.

  • Will Mysql's performance drop sharply when the data volume of the table exceeds 10 million?

Answer: No! Mysql is a database, not a file. As the number of data rows increases, performance will decrease, but these decreases are not linear. If the user chooses the correct storage engine and the correct configuration, MySQL can withstand more data. .
数据库和传统系统文件的区别是在于数据库支持事务

1.5 Storage engine related operation syntax

  • View the storage engines currently supported by Mysql database
show engines\G;

Insert image description here

1.6 Connect to Mysql

连接Mysql操作是一个连接进程和Mysql数据库实例进行通信

  • TCP/IP

The TCP/IP socket method is the method provided by the Mysql database on any platform, and it is also the most commonly used method on the network. This method establishes a network-based connection request over a TCP/IP connection.

mysql -h127.0.0.1 -u david -p 

Note: When connecting to a MYSQL instance through TCP/IP, the MYSQL database will check a permission view online to determine whether the client IP that initiated the request is running and connected to the Mysql instance.

use mysql;
select host,user from user;

Insert image description here

The four users in the table can only connect to the mysql instance locally through localhost.

  • Named pipes and shared memory

When using pipe communication, mysql requires options enabled in the configuration file --enable-named-pipe. In versions after mysql 4.1, mysql also provides a shared memory connection method, which is --shared-memoryimplemented by adding it in the configuration file. --protocol=memoryIf you want to use the shared memory connection method, the Mysql client must also use the option when connecting

Guess you like

Origin blog.csdn.net/qq_43456605/article/details/132757137