LOCK INSTANCE FOR BACKUP UNLOCK INSTANCE
LOCK INSTANCE FOR BACKUP 获得实例级 backup lock,允许在线备份时使用 DML,同时防止可能导致快照不一致的操作。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句需要 BACKUP_ADMIN权限。BACKUP_ADMIN权限会自动授予拥有 RELOAD 权限的用户,适用于从早期版本升级到 MySQL 8.4。Executing the LOCK INSTANCE FOR BACKUP
statement requires the BACKUP_ADMIN
privilege. The BACKUP_ADMIN
privilege is automatically granted to users with the
RELOAD privilege when performing an
in-place upgrade to MySQL 8.4 from an earlier
version.
多个会话可以同时持有备份锁。Multiple sessions can hold a backup lock simultaneously.
UNLOCK INSTANCE 释放当前会话持有的备份锁。会话被终止时,会话持有的备份锁也会被释放。UNLOCK INSTANCE releases a backup lock held by
the current session. A backup lock held by a session is also
released if the session is terminated.
LOCK INSTANCE FOR BACKUP 防止文件被创建、重命名或移除。REPAIR
TABLE TRUNCATE TABLE, OPTIMIZE TABLE,账户管理语句被阻挡。参见 第 15.7.1 节,“账户管理语句”。修改 InnoDB 文件且未记录在 InnoDB 重录日志中的操作也被阻止。LOCK INSTANCE FOR BACKUP prevents files from
being created, renamed, or removed. REPAIR
TABLE TRUNCATE TABLE,
OPTIMIZE TABLE, and account
management statements are blocked. See
Section 15.7.1, “Account Management Statements”. Operations that
modify InnoDB files that are not recorded in
the InnoDB redo log are also blocked.
LOCK INSTANCE FOR BACKUP 允许仅影响用户创建的临时表的 DDL 操作。实际上,属于用户创建的临时表中的文件可以在备份锁保持期间被创建、重命名或删除。也允许创建二进制日志文件。LOCK INSTANCE FOR BACKUP permits DDL operations
that only affect user-created temporary tables. 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.
PURGE BINARY LOGS时,无法发布 LOCK INSTANCE FOR BACKUP句,因为该命令通过移除服务器文件违反了备份锁的规则。PURGE BINARY LOGS cannot be issued
while a LOCK INSTANCE FOR BACKUP
statement is in effect for the instance, because it contravenes
the rules of the backup lock by removing files from the server.
通过 LOCK INSTANCE FOR
BACKUP 获取的备份锁独立于事务锁和通过 FLUSH
TABLES tbl_name [,
tbl_name] ... WITH READ LOCK 获取的锁,并且允许以下语句序列:A backup lock acquired by LOCK INSTANCE FOR
BACKUP is independent of transactional locks and locks
taken by
FLUSH
TABLES ,
and the following sequences of statements are permitted:tbl_name [,
tbl_name] ... WITH READ LOCK
LOCK INSTANCE FOR BACKUP; FLUSH TABLEStbl_name[,tbl_name] ... WITH READ LOCK; UNLOCK TABLES; UNLOCK INSTANCE;
FLUSH TABLEStbl_name[,tbl_name] ... WITH READ LOCK; LOCK INSTANCE FOR BACKUP; UNLOCK INSTANCE; UNLOCK TABLES;
lock_wait_timeout 设置定义了 LOCK INSTANCE FOR
BACKUP 语句在放弃之前等待获取锁的时间。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.