High Performance MySQL (1): Analysis of basic knowledge of MySQL

First, concurrency control

Second, things

2.1 What is the thing

Things are a set of operations on logic, or are executed or not executed.

Four characteristics of things (ACID):

(1) atom: the execution unit is the smallest thing can no longer be divided, ensuring atomicity operation either completed or not completed all;

(2) Consistency: before and after performing the data consistency things, a plurality of the same thing read result data of the same;

(3) Isolation: concurrent access to the database, a user is not something else interference, independent of each other;

(4) Persistence: After submission of a thing, it changed data in the database is persistent, even if they do not change a database failure affecting them.

 

( Default configuration MySQL command-line transactions are automatically submitted , execute SQL statements executed immediately after COMMIT operations, while Oracle does not)

2.3, concurrency problems brought things

Often there will be more things concurrently running the same operating data to complete their tasks, that is, multiple users on the same data manipulation , may cause the following problems:

(1) Dirty read: when a thing is accessing data, and the data is modified, this change has not yet committed to the database, then the other things also access and use this data. Because to read the data has not been submitted so read the "dirty data" dirty data may be incorrect.

(2) loss of Review: When a thing to another thing to read a data also visited the data. After the first thing you modify this data, and the second thing also modify this data, so the first thing to modify the result was lost .

(3) non-repeatable read: reading the same data multiple times within a thing. When this thing is not over yet another thing also access the data, among the first things to read data twice, the second thing due to the modification of the first things that cause data may not be read twice as . Lead to the same thing twice a read data is not the same , that is, non-repeatable read. (Emphasis in the modification)

( 4) Magic Reading : Similar non-repeatable read. It occurs in a few things read data lines, and then inserted into some data other things complicated. To roar query first thing discovered a few more records that do not exist as though hallucinations happened. (Emphasis added or deleted)

 

Non-repeatable read and phantom read difference:

Non-repeatable read focus is modified , such as reading a record many times and found some column values are modified; phantom reads a focus on new or deleted , for example, read many found a record increase or decrease the recording.

2.4, things isolation level

(1) READ_UNCOMMITTED (lowest isolation level) - read uncommitted - dirty reads, phantom reads, non-repeatable read

Yet allowed to read data may result in dirty reads, phantom reads, non-repeatable read

(2) READ_COMMITTED-- the Oracle default - read Submitted - phantom reads, non-repeatable read

Allowing concurrent read data items already submitted, can prevent dirty reads, but phantom reads and non-repeatable reads still occur.

(3) REPEATABLE_READ-- MySQL default - repeatable read - Magic Reading

On the same field repeatedly reading the same result (unless modified itself things), you can prevent dirty reads and non-repeatable read, phantom read may still occur

(4) SERIALIZABLE (highest level of isolation) - serializable - can be prevented

Full compliance ACID isolation levels, followed by the implementation of all things, prevents dirty reads, non-repeatable read, phantom read. But the performance is not good is not commonly used

 

2.5, a database of three paradigms

The first paradigm (1NF) : emphasized that the atomic columns, i.e., columns not be subdivided into several other columns;

The second paradigm (2NF) : First 1NF, further comprising two parts, one table must have a primary key; the second is not contained in the master key must be entirely dependent on the primary key, but can not rely only on a part of the primary key;

The third paradigm (3NF) : First, 2NF, additional non-primary key column must be directly dependent on the primary key, you can not rely on the presence of transfer. I.e. not exist: A case of non-primary key column depends on the non-primary key columns B, non-primary key column B is dependent on the primary key.

(3NF 2NF and confusing: 2NF-- non-primary key column is completely dependent on the primary key, or dependent on the part of the primary key; 3NF-- non-primary key column is directly dependent on the primary key, or depend directly on the non-primary key column)

Third, multi-version concurrency control (MVCC)

Only InnoDB support. Cope with high concurrent transactions, MVCC is more efficient than simply locking, MVCC only "read committed" and "repeatable read" isolation level work, MVCC can use optimistic locking, pessimistic locking is achieved, the databases are not uniform MVCC .

......pending upgrade

Fourth, the storage engine

4.1 difference, MyISAM and InnoDB's

(1) different versions of MySQL default storage engine different: MyISAM is the default engine versions prior to 5.5, InnoDB is after the 5.5 version;

(2) supports row-level locking: MyISAM supports only table-level locking, InnoDB is to support and table-level locking and support row-level locking, the default is row-level locking;

(3) whether to support things and crash recovery: MyISAM stressed that the performance of each query be atomic, faster than InnoDB faster (not absolute) , but does not provide support for things, not crash recovery; InnoDB  provides support and things external key functions, with things (commit), rollback, crash recovery, things safe (ACID)

(4) whether to support foreign keys: MyISAM does not support, InnoDB support;

(5) whether to support multi-version concurrency control ( MVCC ): Only InnoDB support, to deal with high concurrency MVCC things than simply locking more efficient.

 

 

Five, MySQL master-slave replication (own work function)

Mysql installation environment Reference:  https://blog.csdn.net/a774630093/article/details/79270080

Turn off the firewall systemctl stop firewalld.service

5.1, copy the master-slave principle 

There is a log called MySQL bin log (binary log binLog), the log will record all SQL statements to modify the database. The main principle is to be copied from the copy bin logs on the primary server to perform again from the server, so that from the data on the server and data on the same host server.

 

Question 1 : If the MySQL Cluster, what issues need to be considered? - real-time data synchronization can be achieved by copying from the master.

Question 2 : accidentally deleted a table of how to do? - All changes are available to binLog file to find the log, and then resume on the line

5.2, master-slave replication purposes

Can be achieved by copying the data from the backup master, failover, high availability, clusters , separate read and write

5.3, from the master copy configuration

The primary server node:

vi /etc/my.cnf  新增以下内容
server_id=177  ###服务器id
log-bin=mysql-bin   ###开启日志文件
重启mysql服务 service mysqld restart
验证是否已经配置成功
show variables like '%server_id%';
能够查询对应配置文件中的server_id 说明已经配置成功
show master status;
能够看到同步的文件,和行数 说明已经配置成功。

From the server node:

克隆服务器
vi /etc/my.cnf
server_id=178  ###从服务器server_id
log-bin=mysql-bin  ###日志文件同步方式
binlog_do_db=test   ###同步数据库


重启mysql服务 service mysqld restart
验证是否已经配置成功
show variables like '%server_id%';
能够查询对应配置文件中的server_id 说明已经配置成功

从服务器同步主服务器配置
change master to master_host='192.168.212.200',master_user='root',master_password='root',
         master_log_file='mysql-bin.000002',master_log_pos=216;
开始同步 
start slave
检查从服务器复制功能状态
SHOW SLAVE STATUS

Fatal error: The slave I/O thread stops because master and slave have equal MySQL server UUIDs; these UUIDs must be different for replication to work.

解决办法
因为服务器克隆的时候交UUID产生了重复 ,解决办法

Cat  /etc/my.cnf
cd /var/lib/mysql
rm -rf auto.cnf
重启服务器即可
service mysqld restart

 

 

Next: https://mp.csdn.net/postedit/103778112

  Reference: "High Performance MySQL Third Edition"

 

### If you have help, welcome thumbs up! comment! Forwarding! Thank you!

Published 52 original articles · won praise 116 · views 50000 +

Guess you like

Origin blog.csdn.net/RuiKe1400360107/article/details/103727285