Lecture 70: The core concept of global lock in MySQL database

1. The concept of global lock

A global lock is to add a lock to the entire database instance. The global lock is for the entire database instance, not a single database. After adding the lock, the instance will be in a read-only state. At this time, all databases can only perform read operations. For Update and delete operations will be blocked.

A typical application scenario of global lock is to logically back up the entire database, which requires that the data associated with the business tables must ensure consistency and integrity. At this time, all databases can be locked through global lock to avoid the backup process. Data is generated, resulting in data inconsistency.

Let's think about a question together, why is it necessary to lock the backup of the entire database logic? Backup takes time and is not user-friendly.

First of all, let's be clear. We are not backing up the database, but on the basis of backing up the database, we also need to back up the logical dependencies between business tables to ensure data consistency.

First, let’s take a look at the problems that may arise in backup of business tables without using global locks.

As shown in the figure below, there are three business tables in the database. During backup, one table is backed up one by one. The tb_stock table is backed up first. At this time, data is generated in the tb_order table. There is a business relationship between these two tables. This will lead to data incompleteness.

Supongo que te gusta

Origin blog.csdn.net/weixin_44953658/article/details/134304158
Recomendado
Clasificación