13.3.5 LOCK INSTANCE FOR BACKUP and UNLOCK INSTANCE StatementsLOCK INSTANCE FOR BACKUP语句和UNLOCK INSTANCE语句

LOCK INSTANCE FOR BACKUP

UNLOCK INSTANCE

LOCK INSTANCE FOR BACKUP acquires an instance-level backup lock that permits DML during an online backup while preventing operations that could result in an inconsistent snapshot.LOCK INSTANCE FOR BACKUP获取实例级备份锁,该锁允许在联机备份期间使用DML,同时防止可能导致快照不一致的操作。

Executing the LOCK INSTANCE FOR BACKUP statement requires the BACKUP_ADMIN privilege. 执行LOCK INSTANCE FOR BACKUP语句需要BACKUP_ADMIN权限。The BACKUP_ADMIN privilege is automatically granted to users with the RELOAD privilege when performing an in-place upgrade to MySQL 8.0 from an earlier version.当执行从早期版本到MySQL 8.0的就地升级时,具有RELOAD权限的用户将自动获得BACKUP_ADMIN权限。

Multiple sessions can hold a backup lock simultaneously.多个会话可以同时持有备份锁。

UNLOCK INSTANCE releases a backup lock held by the current session. UNLOCK INSTANCE释放当前会话持有的备份锁。A backup lock held by a session is also released if the session is terminated.如果会话终止,会话持有的备份锁也会释放。

LOCK INSTANCE FOR BACKUP prevents files from being created, renamed, or removed. LOCK INSTANCE FOR BACKUP防止创建、重命名或删除文件。REPAIR TABLE TRUNCATE TABLE, OPTIMIZE TABLE, and account management statements are blocked. REPAIR TABLETRUNCATE TABLEOPTIMIZE TABLE和帐户管理报表被阻止。See Section 13.7.1, “Account Management Statements”. 请参阅第13.7.1节,“账户管理语句”Operations that modify InnoDB files that are not recorded in the InnoDB redo log are also blocked.修改未记录在InnoDB重做日志中的InnoDB文件的操作也会被阻止。

LOCK INSTANCE FOR BACKUP permits DDL operations that only affect user-created temporary tables. LOCK INSTANCE FOR BACKUP允许仅影响用户创建的临时表的DDL操作。In effect, files that belong to user-created temporary tables can be created, renamed, or removed while a backup lock is held. 实际上,在保留备份锁时,可以创建、重命名或删除属于用户创建的临时表的文件。Creation of binary log files is also permitted.还允许创建二进制日志文件。

A backup lock acquired by LOCK INSTANCE FOR BACKUP is independent of transactional locks and locks taken by FLUSH TABLES tbl_name [, tbl_name] ... WITH READ LOCK, and the following sequences of statements are permitted:LOCK INSTANCE FOR BACKUP获取的备份锁独立于事务锁和FLUSH TABLES tbl_name [, tbl_name] ... WITH READ LOCK所使用的锁,并且允许以下语句序列:

LOCK INSTANCE FOR BACKUP;
FLUSH TABLES tbl_name [, tbl_name] ... WITH READ LOCK;
UNLOCK TABLES;
UNLOCK INSTANCE;
FLUSH TABLES tbl_name [, tbl_name] ... WITH READ LOCK;
LOCK INSTANCE FOR BACKUP;
UNLOCK INSTANCE;
UNLOCK TABLES;

The lock_wait_timeout setting defines the amount of time that a LOCK INSTANCE FOR BACKUP statement waits to acquire a lock before giving up.lock_wait_timeout设置定义LOCK INSTANCE FOR BACKUP语句在放弃前等待获取锁的时间量。